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

GO-3757 graceful shutdown for long objectstore queries #1388

Merged
merged 2 commits into from
Jul 12, 2024

Conversation

requilence
Copy link
Contributor

  • add isClosingCh for the objectstore
  • add waitgroup for store queries that are using iterator
  • fail long queries fast when isClosingCh is closed. (not possible for all queries, requires refactoring)
  • wait all queries to finish on objectStore close

@requilence requilence requested a review from deff7 July 12, 2024 08:28
Copy link

coderabbitai bot commented Jul 12, 2024

Warning

Rate limit exceeded

@requilence has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 44 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 49d46f8 and 8a59cb5.

Walkthrough

The changes introduce concurrency management and graceful shutdown capabilities to the dsObjectStore in the localstore package. New fields and methods were added to manage and monitor running queries using sync.WaitGroup and a closing channel. This ensures that ongoing database operations are handled properly during the store's closing process, preventing abrupt terminations and potential data inconsistency.

Changes

File Path Change Summary
pkg/lib/localstore/objectstore/indexer_store.go Added concurrency management with runningQueriesWG to BatchProcessFullTextQueue and ListIDsFromFullTextQueue methods.
pkg/lib/localstore/objectstore/links.go Added concurrency management with runningQueriesWG to GetWithLinksInfoByID, GetOutboundLinksByID, and GetInboundLinksByID methods.
pkg/lib/localstore/objectstore/objects.go Introduced ErrStoreIsClosing, enhanced New() function, modified Close() and ListIds() to handle long queries during shutdown.
pkg/lib/localstore/objectstore/queries.go Added isClosing() method and integrated it into queryRaw and QueryFromFulltext for graceful termination handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant dsObjectStore
    participant DB
    participant Error

    Note over dsObjectStore: Store is Running
    Client->>dsObjectStore: BatchProcessFullTextQueue
    dsObjectStore->>DB: fetch IDs for processing
    DB-->>dsObjectStore: return IDs
    dsObjectStore->>Client: process IDs

    Note over dsObjectStore: Store is Closing
    Client->>dsObjectStore: BatchProcessFullTextQueue
    dsObjectStore->>Error: return ErrStoreIsClosing
    Error-->>Client: Store is closing
Loading

Poem

When stores must close, but tasks still run,
We sync our queries, one by one.
With channels and waits, we keep things smooth,
Ensuring that no data will move.
Graceful endings, a tidy fix,
For code that through the data ticks.


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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

Copy link

@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 2b89553 and 49d46f8.

Files selected for processing (4)
  • pkg/lib/localstore/objectstore/indexer_store.go (2 hunks)
  • pkg/lib/localstore/objectstore/links.go (3 hunks)
  • pkg/lib/localstore/objectstore/objects.go (5 hunks)
  • pkg/lib/localstore/objectstore/queries.go (4 hunks)
Additional comments not posted (12)
pkg/lib/localstore/objectstore/links.go (3)

20-22: LGTM! Tracking running queries with runningQueriesWG.

The changes correctly add the query to the WaitGroup and ensure it is decremented when the query is done.


68-69: LGTM! Tracking running queries with runningQueriesWG.

The changes correctly add the query to the WaitGroup and ensure it is decremented when the query is done.


80-81: LGTM! Tracking running queries with runningQueriesWG.

The changes correctly add the query to the WaitGroup and ensure it is decremented when the query is done.

pkg/lib/localstore/objectstore/indexer_store.go (2)

22-23: LGTM! Tracking running queries with runningQueriesWG and handling store closing.

The changes correctly add the query to the WaitGroup, handle the closing state, and ensure the query is properly managed.

Also applies to: 30-31


47-48: LGTM! Tracking running queries with runningQueriesWG.

The changes correctly add the query to the WaitGroup and ensure it is decremented when the query is done.

pkg/lib/localstore/objectstore/objects.go (4)

195-196: LGTM! Adding fields for managing running queries and closing state.

The added fields runningQueriesWG and isClosingCh are correctly introduced to manage running queries and handle the closing state.


64-64: LGTM! Initializing the isClosingCh channel.

The isClosingCh channel is correctly initialized in the New method.


213-216: LGTM! Handling store closing by closing isClosingCh and waiting for running queries.

The Close method correctly handles the closing state by closing the isClosingCh channel and waiting for all running queries to complete using runningQueriesWG.


354-355: LGTM! Tracking running queries with runningQueriesWG.

The changes correctly add the query to the WaitGroup and ensure it is decremented when the query is done.

pkg/lib/localstore/objectstore/queries.go (3)

101-108: LGTM! Adding isClosing method to check store closing state.

The isClosing method is correctly implemented to check if the store is closing by using the isClosingCh channel.


122-123: LGTM! Tracking running queries with runningQueriesWG and handling store closing.

The changes correctly add the query to the WaitGroup, handle the closing state, and ensure the query is properly managed.

Also applies to: 131-133, 144-146


186-188: LGTM! Handling store closing during full-text queries.

The changes correctly handle the store's closing state during full-text queries by checking the isClosing method and returning ErrStoreIsClosing if the store is closing.

Copy link

New Coverage 46.8% of statements
Patch Coverage 76.9% of changed statements (40/52)

Coverage provided by https://github.com/seriousben/go-patch-cover-action

@requilence requilence merged commit 7a04525 into main Jul 12, 2024
5 checks passed
@requilence requilence deleted the go-3757-badger-panics-on-close branch July 12, 2024 10:04
@github-actions github-actions bot locked and limited conversation to collaborators Jul 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants