Skip to content
New issue

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

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

Already on GitHub? # to your account

[ISSUE #2336]🤡Implement PopLongPollingService notifyMessageArriving🧑‍💻 #2337

Merged
merged 1 commit into from
Jan 19, 2025

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Jan 19, 2025

Which Issue(s) This PR Fixes(Closes)

Fixes #2336

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced long polling service with improved message filtering and state management
    • Added configurable polling map size for broker configuration
  • Improvements

    • Upgraded concurrency capabilities with crossbeam-skiplist dependency
    • Improved type safety for pop message processing
    • Updated PopRequest to support better shared state management
  • Technical Updates

    • Introduced generic struct for long polling service
    • Modified message request handling mechanisms

Copy link
Contributor

coderabbitai bot commented Jan 19, 2025

Walkthrough

This pull request introduces enhancements to the RocketMQ broker's long polling service and related components. The changes include adding a new dependency crossbeam-skiplist, modifying the PopLongPollingService to be generic, updating the PopRequest struct to support shared atomic boolean state, and extending the BrokerConfig with a new polling map size configuration. These modifications aim to improve the flexibility and concurrency capabilities of the message processing system.

Changes

File Change Summary
rocketmq-broker/Cargo.toml Added crossbeam-skiplist = "0.1" dependency
rocketmq-broker/src/long_polling/long_polling_service/pop_long_polling_service.rs - Made PopLongPollingService generic
- Added new methods: new(), wake_up(), poll_remoting_commands()
- Modified notify_message_arriving() to return bool
rocketmq-broker/src/long_polling/pop_request.rs - Added Clone trait
- Changed complete field to Arc<AtomicBool>
rocketmq-broker/src/processor/pop_message_processor.rs - Updated pop_long_polling_service to be generic
- Modified service initialization
rocketmq-common/src/common/broker/broker_config.rs - Added pop_polling_map_size field
- Set default value to 100000

Assessment against linked issues

Objective Addressed Explanation
Implement PopLongPollingService notifyMessageArriving [#2336]

Possibly related PRs

Suggested labels

feature🚀, auto merge, ready to review, waiting-review, AI review first, rocketmq-broker crate

Suggested reviewers

  • TeslaRustor
  • SpaceXCN
  • rocketmq-rust-bot

Poem

🚀 In the realm of message flow,
Where polling services grow,
A skiplist dance, atomic and bright,
Concurrency leaps to a new height!
RocketMQ's magic, code so clean,
A rabbit's dream of speed unseen! 🐰


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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.

@rocketmq-rust-bot
Copy link
Collaborator

🔊@mxsm 🚀Thanks for your contribution🎉!

💡CodeRabbit(AI) will review your code first🔥!

Note

🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥.

Copy link

codecov bot commented Jan 19, 2025

Codecov Report

Attention: Patch coverage is 1.25000% with 79 lines in your changes missing coverage. Please review.

Project coverage is 28.22%. Comparing base (2caa670) to head (fbf684e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...g/long_polling_service/pop_long_polling_service.rs 0.00% 74 Missing ⚠️
...etmq-broker/src/processor/pop_message_processor.rs 0.00% 4 Missing ⚠️
rocketmq-broker/src/long_polling/pop_request.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2337      +/-   ##
==========================================
- Coverage   28.25%   28.22%   -0.03%     
==========================================
  Files         504      504              
  Lines       72500    72577      +77     
==========================================
+ Hits        20485    20486       +1     
- Misses      52015    52091      +76     

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

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

🔭 Outside diff range comments (1)
rocketmq-broker/src/long_polling/pop_request.rs (1)

Line range hint 34-55: Correct the complete method implementation

The complete method uses unwrap_or_default() on the result of compare_exchange, which may not accurately reflect whether the atomic exchange was successful. Using is_ok() will return a boolean indicating if the state was successfully changed from false to true.

Apply this diff to fix the method:

     pub fn complete(&self) -> bool {
         self.complete
             .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
-            .unwrap_or_default()
+            .is_ok()
     }
🧹 Nitpick comments (3)
rocketmq-common/src/common/broker/broker_config.rs (2)

203-203: Add documentation for pop_polling_map_size

The new field pop_polling_map_size has been added to BrokerConfig. To improve maintainability and clarity, consider adding documentation comments to explain its purpose, default value, and how it affects the system.


309-309: Consider making pop_polling_map_size configurable

Currently, pop_polling_map_size is set to 100000. If this value might need to be adjusted based on deployment size or performance considerations, consider exposing it as a configurable parameter through a configuration file or command-line argument.

rocketmq-broker/src/processor/pop_message_processor.rs (1)

104-107: Document the purpose of the boolean parameter.

The false parameter's purpose is not immediately clear. Consider adding a named parameter or documentation to clarify its intent.

Apply this diff to improve clarity:

-            pop_long_polling_service: ArcMut::new(PopLongPollingService::new(
-                broker_runtime_inner.clone(),
-                false,
-            )),
+            pop_long_polling_service: ArcMut::new(PopLongPollingService::new(
+                broker_runtime_inner.clone(),
+                is_order_enabled: false, // Document why this is false by default
+            )),
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2caa670 and fbf684e.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • rocketmq-broker/Cargo.toml (1 hunks)
  • rocketmq-broker/src/long_polling/long_polling_service/pop_long_polling_service.rs (3 hunks)
  • rocketmq-broker/src/long_polling/pop_request.rs (2 hunks)
  • rocketmq-broker/src/processor/pop_message_processor.rs (2 hunks)
  • rocketmq-common/src/common/broker/broker_config.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: build (windows-latest, nightly)
  • GitHub Check: build (windows-latest, stable)
  • GitHub Check: build (macos-latest, nightly)
  • GitHub Check: build (macos-latest, stable)
  • GitHub Check: test
  • GitHub Check: build (ubuntu-latest, nightly)
  • GitHub Check: build
  • GitHub Check: build (ubuntu-latest, stable)
  • GitHub Check: auto-approve
🔇 Additional comments (3)
rocketmq-broker/src/long_polling/long_polling_service/pop_long_polling_service.rs (1)

88-113: Handle unmatched messages appropriately in notify_message_arriving

When match_result is false, the code re-inserts the pop_request into remoting_commands. However, since pop_request was removed using pop_front or pop_back, re-inserting it might cause inconsistencies or race conditions. Ensure that the concurrency control is properly managed when modifying the remoting_commands set.

rocketmq-broker/src/long_polling/pop_request.rs (1)

30-30: Verify that deriving Clone for PopRequest is safe

By adding #[derive(Clone)], all fields within PopRequest are now cloned when clone() is called. Ensure that this behavior is safe and that deep copies of fields like Arc<AtomicBool> and Arc<Box<dyn MessageFilter>> do not lead to unintended side effects or performance issues.

rocketmq-broker/src/processor/pop_message_processor.rs (1)

85-85: LGTM! Generic type parameter addition improves type safety.

The change to make PopLongPollingService generic over MS aligns with the generic context of the containing struct.

Comment on lines +129 to +131
pub fn wake_up(&self, pop_request: PopRequest) -> bool {
unimplemented!("PopLongPollingService::wake_up")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement the wake_up method

The wake_up method is currently unimplemented, but it is essential for notifying pop requests when messages arrive. Please provide an implementation to ensure proper functionality of the long polling service.

Comment on lines +144 to +162
loop {
if self.notify_last {
pop_request = remoting_commands
.pop_back()
.map(|entry| entry.value().clone());
} else {
pop_request = remoting_commands
.pop_front()
.map(|entry| entry.value().clone());
}

if let Some(ref request) = pop_request {
self.total_polling_num.fetch_sub(1, Ordering::AcqRel);
} else {
break;
}
}
pop_request
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential infinite loop in poll_remoting_commands method

The loop in the poll_remoting_commands method may not exit as expected. If a pop_request is found (Some), the loop continues without a break condition, which could lead to an infinite loop and drain all entries from remoting_commands. Consider adding a break statement after adjusting total_polling_num to exit the loop appropriately.

Apply this diff to fix the loop:

             loop {
                 if self.notify_last {
                     pop_request = remoting_commands
                         .pop_back()
                         .map(|entry| entry.value().clone());
                 } else {
                     pop_request = remoting_commands
                         .pop_front()
                         .map(|entry| entry.value().clone());
                 }

                 if let Some(ref request) = pop_request {
                     self.total_polling_num.fetch_sub(1, Ordering::AcqRel);
+                    break; // Exit the loop after processing a pop_request
                 } else {
                     break;
                 }
             }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
loop {
if self.notify_last {
pop_request = remoting_commands
.pop_back()
.map(|entry| entry.value().clone());
} else {
pop_request = remoting_commands
.pop_front()
.map(|entry| entry.value().clone());
}
if let Some(ref request) = pop_request {
self.total_polling_num.fetch_sub(1, Ordering::AcqRel);
} else {
break;
}
}
pop_request
}
loop {
if self.notify_last {
pop_request = remoting_commands
.pop_back()
.map(|entry| entry.value().clone());
} else {
pop_request = remoting_commands
.pop_front()
.map(|entry| entry.value().clone());
}
if let Some(ref request) = pop_request {
self.total_polling_num.fetch_sub(1, Ordering::AcqRel);
break; // Exit the loop after processing a pop_request
} else {
break;
}
}
pop_request

Comment on lines +57 to +59

crossbeam-skiplist = "0.1"

Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update crossbeam-skiplist to version 0.1.3

The current version "0.1" should be updated to "0.1.3" to get the latest fixes. The package is actively maintained (last updated January 2024) and has no known security vulnerabilities.

🔗 Analysis chain

Verify the version of crossbeam-skiplist.

The version "0.1" seems outdated. Let's verify if a newer version is available and check for any security advisories.

Run this script to check available versions and security advisories:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for latest versions and security advisories of crossbeam-skiplist

# Check crates.io for latest versions
curl -s https://crates.io/api/v1/crates/crossbeam-skiplist | jq '.crate.max_version'

# Check for security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: RUST, package: "crossbeam-skiplist") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 445


Script:

#!/bin/bash
# Check the last update time and repository info for crossbeam-skiplist
curl -s https://crates.io/api/v1/crates/crossbeam-skiplist | jq '{updated_at: .crate.updated_at, repository: .crate.repository}'

Length of output: 246

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

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

LGTM

@rocketmq-rust-bot rocketmq-rust-bot merged commit ddc044b into main Jan 19, 2025
25 of 27 checks passed
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Jan 19, 2025
@mxsm mxsm deleted the feature-2336 branch January 19, 2025 15:01
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
AI review first Ai review pr first approved PR has approved auto merge feature🚀 Suggest an idea for this project. rocketmq-broker crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature🚀] Implement PopLongPollingService notifyMessageArriving
3 participants