Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix NGT flush logic #2598

Merged
merged 17 commits into from
Sep 11, 2024
Merged

Bugfix NGT flush logic #2598

merged 17 commits into from
Sep 11, 2024

Conversation

hlts2
Copy link
Collaborator

@hlts2 hlts2 commented Sep 9, 2024

Description

If a CRUD operation such as insert is executed again after flush, a nil pointer error occurred.
Initialize with the RegenerateIndexes function, but do not rewrite the receiver. So I changed that the field is override.

Related Issue

Versions

  • Vald Version: v1.7.13
  • Go Version: v1.23.0
  • Rust Version: v1.80.0
  • Docker Version: v27.1.1
  • Kubernetes Version: v1.30.3
  • Helm Version: v3.15.3
  • NGT Version: v2.2.4
  • Faiss Version: v1.8.0

Checklist

Special notes for your reviewer

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Adjusted the logic for directory deletion based on the memory state, ensuring proper handling when the inMem flag is false.
    • Enhanced checks in key methods to prevent nil pointer dereferences, ensuring valid lengths are returned only when the instance is in a proper state.
    • Improved error handling in index creation methods to provide clearer feedback when flushing is in progress.
  • New Features

    • Introduced a new method for copying ngt instances, enhancing state duplication.
    • Added a method for loading index statistics, promoting better organization of the code.

Copy link
Contributor

coderabbitai bot commented Sep 9, 2024

Walkthrough

Walkthrough

The changes involve modifications to the RegenerateIndexes function in the ngt.go file, where the condition checking the inMem state has been inverted to alter when directory deletion occurs. Additionally, the Len, InsertVQueueBufferLen, and DeleteVQueueBufferLen functions have been enhanced with checks for nil pointers and flushing states to improve code robustness. The error handling logic in the CreateIndex and CreateAndSaveIndex methods has been updated to address ongoing flushing processes. A new method copyNGT has been introduced to facilitate copying state between ngt instances.

Changes

Files Change Summary
pkg/agent/core/ngt/service/ngt.go Modified the RegenerateIndexes function to invert the condition checking n.inMem, changing when directory deletion is triggered. Enhanced the Len, InsertVQueueBufferLen, and DeleteVQueueBufferLen functions to include checks for nil pointers and flushing states. Added new methods copyNGT and loadStatistics for better state management and organization.
pkg/agent/core/ngt/handler/grpc/index.go Updated error handling in CreateIndex and CreateAndSaveIndex methods to manage errors related to ongoing flushing processes, returning codes.Aborted when applicable.

Sequence Diagram(s)

sequenceDiagram
    participant NGT as NGT Instance
    participant Directory as Directory System

    NGT->>Directory: Check n.inMem state
    alt n.inMem is true
        Directory-->>NGT: Do not delete directory
    else n.inMem is false
        Directory-->>NGT: Delete directory
    end
Loading
sequenceDiagram
    participant NGT as NGT Instance

    NGT->>NGT: Check state for Len
    alt State is valid
        NGT-->>Caller: Return length
    else State is invalid
        NGT-->>Caller: Return 0
    end

    NGT->>NGT: Check state for InsertVQueueBufferLen
    alt State is valid
        NGT-->>Caller: Return buffer length
    else State is invalid
        NGT-->>Caller: Return 0
    end

    NGT->>NGT: Check state for DeleteVQueueBufferLen
    alt State is valid
        NGT-->>Caller: Return buffer length
    else State is invalid
        NGT-->>Caller: Return 0
    end
Loading
sequenceDiagram
    participant Server as gRPC Server

    Server->>Server: Call CreateIndex
    alt Flushing in progress
        Server-->>Client: Return error codes.Aborted
    else No flushing
        Server-->>Client: Proceed with index creation
    end

    Server->>Server: Call CreateAndSaveIndex
    alt Flushing in progress
        Server-->>Client: Return error codes.Aborted
    else No flushing
        Server-->>Client: Proceed with index creation and saving
    end
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Sep 9, 2024

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b17cc73 and 4a90356.

Files selected for processing (1)
  • pkg/agent/core/ngt/service/ngt.go (1 hunks)

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 28.20513% with 28 lines in your changes missing coverage. Please review.

Project coverage is 24.37%. Comparing base (f418cc9) to head (c293365).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/agent/core/ngt/service/ngt.go 33.33% 22 Missing ⚠️
pkg/agent/core/ngt/handler/grpc/index.go 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2598      +/-   ##
==========================================
- Coverage   24.53%   24.37%   -0.17%     
==========================================
  Files         530      531       +1     
  Lines       45522    45867     +345     
==========================================
+ Hits        11171    11182      +11     
- Misses      33602    33934     +332     
- Partials      749      751       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cloudflare-workers-and-pages bot commented Sep 9, 2024

Deploying vald with  Cloudflare Pages  Cloudflare Pages

Latest commit: c293365
Status: ✅  Deploy successful!
Preview URL: https://25714553.vald.pages.dev
Branch Preview URL: https://fix-ngt-index.vald.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4a90356 and 50861c7.

Files selected for processing (1)
  • pkg/agent/core/ngt/service/ngt.go (2 hunks)
Additional context used
GitHub Check: codecov/patch
pkg/agent/core/ngt/service/ngt.go

[warning] 1252-1252: pkg/agent/core/ngt/service/ngt.go#L1252
Added line #L1252 was not covered by tests


[warning] 1947-1947: pkg/agent/core/ngt/service/ngt.go#L1947
Added line #L1947 was not covered by tests


[warning] 1954-1954: pkg/agent/core/ngt/service/ngt.go#L1954
Added line #L1954 was not covered by tests


[warning] 1961-1961: pkg/agent/core/ngt/service/ngt.go#L1961
Added line #L1961 was not covered by tests

pkg/agent/core/ngt/service/ngt.go Show resolved Hide resolved
pkg/agent/core/ngt/service/ngt.go Outdated Show resolved Hide resolved
pkg/agent/core/ngt/service/ngt.go Outdated Show resolved Hide resolved
pkg/agent/core/ngt/service/ngt.go Outdated Show resolved Hide resolved
Signed-off-by: hlts2 <[email protected]>
coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 9, 2024
@hlts2 hlts2 requested review from kpango and vankichi September 9, 2024 05:37
@hlts2 hlts2 self-assigned this Sep 9, 2024
Signed-off-by: hlts2 <[email protected]>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 50861c7 and d27ba65.

Files selected for processing (1)
  • pkg/agent/core/ngt/service/ngt.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/agent/core/ngt/service/ngt.go

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 9, 2024
Comment on lines +1305 to 1309
case n.IsFlushing():
return errors.ErrFlushingIsInProgress
}

ic := n.vq.IVQLen() + n.vq.DVQLen()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Added logic to check if a vqueue reference could be nil if a flush is running.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d27ba65 and 3433f28.

Files selected for processing (1)
  • pkg/agent/core/ngt/service/ngt.go (4 hunks)
Files skipped from review due to trivial changes (1)
  • pkg/agent/core/ngt/service/ngt.go

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 9, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9d1f550 and 9588ef3.

Files selected for processing (1)
  • pkg/agent/core/ngt/service/ngt.go (5 hunks)
Additional comments not posted (2)
pkg/agent/core/ngt/service/ngt.go (2)

1302-1309: Verify the handling of delete and insert operations in CreateIndex.

The function CreateIndex handles index creation by processing delete and insert operations from the vector queue. It is crucial to verify that these operations maintain data integrity and that the conditions under which they are processed are correctly implemented.

Verification successful

Verification Successful: Handling of Delete and Insert Operations in CreateIndex

The CreateIndex function's handling of delete and insert operations is adequately tested across various test files in the codebase. These tests ensure that the function maintains data integrity and correctly processes operations under different conditions.

  • The function is referenced in multiple test files, indicating comprehensive testing coverage.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of delete and insert operations in `CreateIndex`.

# Test: Search for the function usage and check the handling of operations.
rg --type go -A 10 $'CreateIndex'

Length of output: 256432


Line range hint 1252-1281: Verify the handling of new instance creation in RegenerateIndexes.

The function RegenerateIndexes correctly handles the regeneration of indexes by locking and setting appropriate flags. However, the transfer of settings and configurations to the new instance should be explicitly verified to ensure that all parameters are correctly applied.

pkg/agent/core/ngt/service/ngt.go Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 10, 2024
Copy link
Contributor

Signed-off-by: hlts2 <[email protected]>
@hlts2 hlts2 merged commit c3c5765 into main Sep 11, 2024
44 of 47 checks passed
@hlts2 hlts2 deleted the fix/ngt/index branch September 11, 2024 02:02
vdaas-ci pushed a commit that referenced this pull request Sep 11, 2024
* fix: bugfix flush logic

Signed-off-by: hlts2 <[email protected]>

* fix: nil check for flushing

Signed-off-by: hlts2 <[email protected]>

* fix: add flush check logic

Signed-off-by: hlts2 <[email protected]>

* fix: nil check bug

Signed-off-by: hlts2 <[email protected]>

* fix: add nil check

Signed-off-by: hlts2 <[email protected]>

* fix: return err when the flush process is executing

Signed-off-by: hlts2 <[email protected]>

* fix: add error check for flushing

Signed-off-by: hlts2 <[email protected]>

* fix: error message

Signed-off-by: hlts2 <[email protected]>

* fix: disable kvs and vqueue initialization

Signed-off-by: hlts2 <[email protected]>

* fix: disable commentout

Signed-off-by: hlts2 <[email protected]>

* fix: disable kvs and vq

Signed-off-by: hlts2 <[email protected]>

* fix: nil set to kvs and vq

Signed-off-by: hlts2 <[email protected]>

* fix: copy ngt service object for flushing

Signed-off-by: hlts2 <[email protected]>

* fix: deleted unnecessary nil check

Signed-off-by: hlts2 <[email protected]>

* fix: variable name

Signed-off-by: hlts2 <[email protected]>

---------

Signed-off-by: hlts2 <[email protected]>
Co-authored-by: Yusuke Kato <[email protected]>
vankichi added a commit that referenced this pull request Sep 11, 2024
* fix: bugfix flush logic



* fix: nil check for flushing



* fix: add flush check logic



* fix: nil check bug



* fix: add nil check



* fix: return err when the flush process is executing



* fix: add error check for flushing



* fix: error message



* fix: disable kvs and vqueue initialization



* fix: disable commentout



* fix: disable kvs and vq



* fix: nil set to kvs and vq



* fix: copy ngt service object for flushing



* fix: deleted unnecessary nil check



* fix: variable name



---------

Signed-off-by: hlts2 <[email protected]>
Co-authored-by: Hiroto Funakoshi <[email protected]>
Co-authored-by: Yusuke Kato <[email protected]>
Co-authored-by: Kiichiro YUKAWA <[email protected]>
@kpango kpango mentioned this pull request Oct 11, 2024
takuyaymd pushed a commit to takuyaymd/vald that referenced this pull request Dec 2, 2024
* fix: bugfix flush logic

Signed-off-by: hlts2 <[email protected]>

* fix: nil check for flushing

Signed-off-by: hlts2 <[email protected]>

* fix: add flush check logic

Signed-off-by: hlts2 <[email protected]>

* fix: nil check bug

Signed-off-by: hlts2 <[email protected]>

* fix: add nil check

Signed-off-by: hlts2 <[email protected]>

* fix: return err when the flush process is executing

Signed-off-by: hlts2 <[email protected]>

* fix: add error check for flushing

Signed-off-by: hlts2 <[email protected]>

* fix: error message

Signed-off-by: hlts2 <[email protected]>

* fix: disable kvs and vqueue initialization

Signed-off-by: hlts2 <[email protected]>

* fix: disable commentout

Signed-off-by: hlts2 <[email protected]>

* fix: disable kvs and vq

Signed-off-by: hlts2 <[email protected]>

* fix: nil set to kvs and vq

Signed-off-by: hlts2 <[email protected]>

* fix: copy ngt service object for flushing

Signed-off-by: hlts2 <[email protected]>

* fix: deleted unnecessary nil check

Signed-off-by: hlts2 <[email protected]>

* fix: variable name

Signed-off-by: hlts2 <[email protected]>

---------

Signed-off-by: hlts2 <[email protected]>
Co-authored-by: Yusuke Kato <[email protected]>
takuyaymd pushed a commit to takuyaymd/vald that referenced this pull request Dec 2, 2024
* fix: bugfix flush logic

Signed-off-by: hlts2 <[email protected]>

* fix: nil check for flushing

Signed-off-by: hlts2 <[email protected]>

* fix: add flush check logic

Signed-off-by: hlts2 <[email protected]>

* fix: nil check bug

Signed-off-by: hlts2 <[email protected]>

* fix: add nil check

Signed-off-by: hlts2 <[email protected]>

* fix: return err when the flush process is executing

Signed-off-by: hlts2 <[email protected]>

* fix: add error check for flushing

Signed-off-by: hlts2 <[email protected]>

* fix: error message

Signed-off-by: hlts2 <[email protected]>

* fix: disable kvs and vqueue initialization

Signed-off-by: hlts2 <[email protected]>

* fix: disable commentout

Signed-off-by: hlts2 <[email protected]>

* fix: disable kvs and vq

Signed-off-by: hlts2 <[email protected]>

* fix: nil set to kvs and vq

Signed-off-by: hlts2 <[email protected]>

* fix: copy ngt service object for flushing

Signed-off-by: hlts2 <[email protected]>

* fix: deleted unnecessary nil check

Signed-off-by: hlts2 <[email protected]>

* fix: variable name

Signed-off-by: hlts2 <[email protected]>

---------

Signed-off-by: hlts2 <[email protected]>
Co-authored-by: Yusuke Kato <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants