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-3354 subscription publish undetermined order #1171

Merged
merged 6 commits into from
Apr 23, 2024

Conversation

requilence
Copy link
Contributor

@requilence requilence commented Apr 23, 2024

Summary by CodeRabbit

  • New Features

    • Introduced asynchronous message publishing with PublishAsync to ensure non-blocking operations while maintaining the order of messages.
  • Enhancements

    • Improved the Close method to ensure proper closure of the publishQueue.
    • Enhanced the Publish method with a subscription status check prior to publishing.
  • Bug Fixes

    • Modified test cases to better validate the sequential order of object updates, ensuring data consistency and integrity.
  • Refactor

    • Updated loop iterations in sendUpdatesToSubscriptions to enhance performance and readability by using range-based loops.

@requilence requilence requested a review from deff7 April 23, 2024 14:58
Copy link

coderabbitai bot commented Apr 23, 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 29 minutes and 41 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 1a480ee and 3b9769a.

Walkthrough

The recent updates focus on enhancing the asynchronous processing capabilities within the subscription and local store systems. New methods for non-blocking message publishing ensure ordered delivery, while tests are adjusted to verify the sequential update process. The overall aim is to improve efficiency and reliability in message handling and data updates across the system.

Changes

File Path Change Summary
pkg/lib/database/subscription.go Introduced asynchronous publishing methods (PublishAsync), added new fields for queue management, and updated existing methods to enhance message processing and subscription checks.
pkg/lib/localstore/objectstore/queries_test.go Modified test to include sequential updates and verifications, enhancing the rigor and structure of testing.
pkg/lib/localstore/objectstore/update.go Replaced Publish with PublishAsync in sendUpdatesToSubscriptions to align with new asynchronous capabilities.

Poem

🐇✨
In the burrows of code, where the data trees grow,
A rabbit hopped in, with updates in tow.
Async in its heart, and order in mind,
It tweaked and it tested, leaving old bugs behind.
Now messages fly, on swift winds they ride,
In the land of the code, with a rabbit as guide.
🌟📬


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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

Out of diff range and nitpick comments (1)
pkg/lib/database/subscription.go (1)

75-108: The processQueue method correctly handles the asynchronous processing of messages. However, consider handling the case where context.Background() might need cancellation support if the system requires graceful shutdowns.

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: 1

Comment on lines 74 to 108
// should be called via sub.processQueueOnce
func (sub *subscription) processQueue() {
go func() {
select {
case <-sub.quit:
err := sub.publishQueue.Close()
if err != nil && !errors.Is(err, mb.ErrClosed) {
log.Errorf("subscription %p failed to close async queue: %s", sub, err)
}
unprocessed := sub.publishQueue.Len()
if unprocessed > 0 {
log.Errorf("subscription %p has %d unprocessed messages in the async queue", sub, unprocessed)
}
}
}()

var (
msg *types.Struct
err error
)
for {
// no need for cancellation here, because we close the queue itself on quit and it will return
msg, err = sub.publishQueue.WaitOne(context.Background())
if err != nil {
if !errors.Is(err, mb.ErrClosed) {
log.Errorf("subscription %p failed to get message from async queue: %s", sub, err)
}
return
}
select {
case sub.ch <- msg:
continue
}
}
}
Copy link

@coderabbitai coderabbitai bot Apr 23, 2024

Choose a reason for hiding this comment

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

The processQueue method handles the asynchronous processing of messages. However, the use of select with a single case in lines 77 and 103 can be simplified to a direct send/receive operation.

- select {
- case <-sub.quit:
+ <-sub.quit
- select {
- case sub.ch <- msg:
+ sub.ch <- msg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks dear little ear, I've fixed this. Here is your carrot 🥕

Copy link

Choose a reason for hiding this comment

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

@requilence, thank you for the update and for the delicious carrot! 🥕 I'm glad to hear that the changes have been made. If there's anything else you need, just let me know!


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Copy link

github-actions bot commented Apr 23, 2024

New Coverage 44.7% of statements
Patch Coverage 0.0% of changed statements (0/30)

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

@fat-fellow fat-fellow changed the title Go 3354 subscription publish undetermined order GO-3354 subscription publish undetermined order Apr 23, 2024
@requilence requilence merged commit f6164d3 into main Apr 23, 2024
5 checks passed
@requilence requilence deleted the go-3354-subscription-publish-undetermined-order branch April 23, 2024 17:10
@github-actions github-actions bot locked and limited conversation to collaborators Apr 23, 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.

2 participants