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

[ISSUE #710]🚀Support pull message result handle-3🎨 #721

Merged
merged 2 commits into from
Jun 30, 2024
Merged

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Jun 30, 2024

(cherry picked from commit 7d2662a0e6a4fa8265f3fca762d96f63ff05a3a7)

Which Issue(s) This PR Fixes(Closes)

Fixes #710

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Introduced PullRequestHoldService to manage suspended pull requests for message processing.
    • Added ManyPullRequest to handle multiple pull requests with synchronization.
  • Enhancements

    • Updated BrokerConfig with new fields for short polling time and long polling enablement.
    • Implemented fmt::Display for various enums and RemotingCommand for better logging and debugging.
  • Bug Fixes

    • Improved handling of PullNotFound in DefaultPullMessageResultHandler.
  • Refactor

    • Renamed modules and methods for better code organization and clarity.
  • API Changes

    • Modified PullMessageRequestHeader to use u64 for suspend_timeout_millis.

(cherry picked from commit 7d2662a0e6a4fa8265f3fca762d96f63ff05a3a7)
Copy link
Contributor

coderabbitai bot commented Jun 30, 2024

Walkthrough

The changes enhance the rocketmq-broker and associated modules, focusing on improvements to the long polling mechanism, logging updates, revisions to pull message handling, and the addition of new configurations and methods. These updates collectively aim to improve the efficiency and functionality of the RocketMQ broker.

Changes

Files/Modules Change Summary
rocketmq-broker/Cargo.toml Added dependency: log = "0.4.22"
rocketmq-broker/src/lib.rs Renamed module longpolling to long_polling
rocketmq-broker/src/long_polling.rs Introduced long_polling_service, many_pull_request, pull_request modules
rocketmq-broker/src/long_polling/long_polling_service/pull_request_hold_service.rs Added PullRequestHoldService struct with methods: new, suspend_pull_request, check_hold_request, notify_message_arriving, notify_message_arriving_ext, notify_master_online, and build_key
rocketmq-broker/src/long_polling/many_pull_request.rs Introduced ManyPullRequest struct with methods: new, add_pull_request, add_pull_requests, clone_list_and_clear, is_empty
rocketmq-broker/src/processor/default_pull_message_result_handler.rs Added #[allow(unused_assignments)] to DefaultPullMessageResultHandler implementation
rocketmq-broker/src/processor/pull_message_processor.rs Moved is_broadcast function to execute_request_when_wakeup
rocketmq-common/src/common/broker/broker_config.rs Updated BrokerConfig struct with new fields: short_polling_time_mills (u64) and long_polling_enable (bool)
rocketmq-remoting/src/protocol.rs Added fmt::Display implementations for LanguageCode and SerializeType enums
rocketmq-remoting/src/protocol/header/pull_message_request_header.rs Changed suspend_timeout_millis field from i64 to u64 in PullMessageRequestHeader
rocketmq-remoting/src/protocol/remoting_command.rs Implemented fmt::Display for RemotingCommand and added method set_suspended_ref

Sequence Diagram

sequenceDiagram
    participant Client
    participant Broker
    participant PullRequestHoldService
    participant ManyPullRequest

    Client->>Broker: Send Pull Request
    Broker->>PullRequestHoldService: Suspend Pull Request
    PullRequestHoldService->>ManyPullRequest: Add Pull Request to List
    ManyPullRequest->>PullRequestHoldService: Confirm Addition

    Note over Client, Broker: Client waits for message
    Broker->>PullRequestHoldService: Notify Message Arrival
    PullRequestHoldService->>ManyPullRequest: Check and Retrieve Requests
    ManyPullRequest->>PullRequestHoldService: Return Pull Requests
    PullRequestHoldService->>Broker: Notify Message to Client
    Broker->>Client: Deliver Message
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement improvements to pull message result handling (710)

Poem

In RocketMQ's bright new day,
Logs now pave the way,
Long polling's here to stay,
Configs set the brokers' sway.
Messages pull with grace,
Through each request's trace,
Rocket fast, a coder’s embrace. 🚀


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are always opted into early access features.

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.

@github-actions github-actions bot requested review from SpaceXCN and TeslaRustor June 30, 2024 15:42
@mxsm
Copy link
Owner Author

mxsm commented Jun 30, 2024

🚀Thanks for your contribution🎉. CodeRabbit(AI) will review your code first🔥

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

Outside diff range and nitpick comments (1)
rocketmq-common/src/common/broker/broker_config.rs (1)

158-159: Add documentation for new fields in BrokerConfig.

The newly added fields short_polling_time_mills and long_polling_enable should have documentation comments to explain their purpose and usage.

/// The time in milliseconds for short polling.
pub short_polling_time_mills: u64,
/// Flag to enable long polling.
pub long_polling_enable: bool,
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a2715c2 and 30270ca.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (12)
  • rocketmq-broker/Cargo.toml (1 hunks)
  • rocketmq-broker/src/lib.rs (1 hunks)
  • rocketmq-broker/src/long_polling.rs (1 hunks)
  • rocketmq-broker/src/long_polling/long_polling_service/pull_request_hold_service.rs (1 hunks)
  • rocketmq-broker/src/long_polling/many_pull_request.rs (1 hunks)
  • rocketmq-broker/src/long_polling/pull_request.rs (1 hunks)
  • rocketmq-broker/src/processor/default_pull_message_result_handler.rs (2 hunks)
  • rocketmq-broker/src/processor/pull_message_processor.rs (2 hunks)
  • rocketmq-common/src/common/broker/broker_config.rs (2 hunks)
  • rocketmq-remoting/src/protocol.rs (3 hunks)
  • rocketmq-remoting/src/protocol/header/pull_message_request_header.rs (2 hunks)
  • rocketmq-remoting/src/protocol/remoting_command.rs (3 hunks)
Files skipped from review due to trivial changes (3)
  • rocketmq-broker/Cargo.toml
  • rocketmq-broker/src/long_polling.rs
  • rocketmq-remoting/src/protocol.rs
Additional comments not posted (31)
rocketmq-broker/src/lib.rs (1)

36-36: LGTM!

The module renaming from longpolling to long_polling improves consistency.

However, ensure the renamed module is correctly referenced throughout the codebase.

Verification successful

LGTM!

The module renaming from longpolling to long_polling has been consistently applied across the codebase.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of the renamed module `long_polling`.

# Test: Search for the usage of the module `long_polling`. Expect: Only occurances of the new module name.
rg --type rust $'long_polling'

Length of output: 853



Script:

#!/bin/bash
# Description: Verify the absence of the old module name `longpolling`.

# Test: Search for the usage of the old module name `longpolling`. Expect: No occurrences of the old module name.
rg --type rust $'longpolling'

Length of output: 28

rocketmq-broker/src/long_polling/many_pull_request.rs (6)

27-32: LGTM!

The new function correctly initializes the ManyPullRequest struct.


34-37: LGTM!

The add_pull_request function correctly adds a single PullRequest to the list.


39-42: LGTM!

The add_pull_requests function correctly adds multiple PullRequest objects to the list.


44-53: LGTM!

The clone_list_and_clear function correctly clones the list and clears it.


60-63: LGTM!

The is_empty function correctly checks if the list is empty.


55-58: Commented-out code.

The get_pull_request_list function is commented out.

rocketmq-broker/src/long_polling/pull_request.rs (9)

36-54: LGTM!

The new function correctly initializes the PullRequest struct.


56-58: LGTM!

The request_command function correctly returns a reference to the request_command field.


60-62: LGTM!

The request_command_mut function correctly returns a mutable reference to the request_command field.


64-66: LGTM!

The client_channel function correctly returns a reference to the client_channel field.


68-70: LGTM!

The pull_from_this_offset function correctly returns the pull_from_this_offset field.


72-74: LGTM!

The subscription_data function correctly returns a reference to the subscription_data field.


76-78: LGTM!

The message_filter function correctly returns a cloned Arc of the message_filter field.


80-82: LGTM!

The timeout_millis function correctly returns the timeout_millis field.


83-85: LGTM!

The suspend_timestamp function correctly returns the suspend_timestamp field.

rocketmq-broker/src/long_polling/long_polling_service/pull_request_hold_service.rs (7)

42-51: LGTM!

The new function correctly initializes the PullRequestHoldService struct.


59-65: LGTM!

The suspend_pull_request function correctly suspends a pull request and adds it to the list.


67-77: LGTM!

The check_hold_request function correctly checks the hold requests.


79-82: LGTM!

The notify_message_arriving function correctly notifies the arrival of a message.


84-158: LGTM!

The notify_message_arriving_ext function correctly notifies the arrival of a message with additional parameters.


160-178: LGTM!

The notify_master_online function correctly notifies that the master is online.


181-183: LGTM!

The build_key function correctly constructs a key from the topic and queue ID.

rocketmq-common/src/common/broker/broker_config.rs (1)

226-227: LGTM!

rocketmq-remoting/src/protocol/header/pull_message_request_header.rs (1)

40-40: Update the type of suspend_timeout_millis to u64.

The type change from i64 to u64 is appropriate for representing timeout values, which are non-negative.

rocketmq-remoting/src/protocol/remoting_command.rs (3)

19-19: Import fmt for Display implementation.

The import of fmt is necessary for the Display trait implementation.


119-138: Implement Display for RemotingCommand.

The implementation provides a detailed string representation of the RemotingCommand struct, which is useful for debugging and logging.


344-347: Add method set_suspended_ref to RemotingCommand.

The new method provides a way to set the suspended field, enhancing the flexibility of the RemotingCommand struct.

rocketmq-broker/src/processor/default_pull_message_result_handler.rs (2)

87-87: Allow unused assignments.

The attribute #[allow(unused_assignments)] is added to suppress warnings about unused assignments, which may be necessary for certain logic flows.


179-197: Handle ResponseCode::PullNotFound in DefaultPullMessageResultHandler.

The added logic handles the scenario where no messages are found for a pull request. It checks for suspend flags and adjusts polling times based on configuration.

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

756-756: Verify the usage of is_broadcast function.

Ensure that the is_broadcast function is correctly implemented and used within this function.

Verification successful

The is_broadcast function is correctly implemented and used.

The function checks if the proxy_pull_broadcast flag is set or if the consumer_group_info indicates a broadcasting message model and passive consume type. The usage of this function in the code is appropriate and aligns with its intended purpose.

  • is_broadcast function implementation is located in rocketmq-broker/src/processor/pull_message_processor.rs at line 760.
  • The function is used at line 756 in the same file.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation and usage of `is_broadcast` function.

# Test: Search for the function implementation. Expect: Only one occurrence.
rg --type rust $'fn is_broadcast'

Length of output: 118



Script:

#!/bin/bash
# Description: Extract the definition and all usages of the `is_broadcast` function within the file `rocketmq-broker/src/processor/pull_message_processor.rs`.

# Extract the definition of `is_broadcast`.
rg --type rust --context 5 'fn is_broadcast' rocketmq-broker/src/processor/pull_message_processor.rs

# Extract all usages of `is_broadcast` within the file.
rg 'is_broadcast' rocketmq-broker/src/processor/pull_message_processor.rs

Length of output: 582



Script:

#!/bin/bash
# Description: Extract the complete implementation of the `is_broadcast` function from the file `rocketmq-broker/src/processor/pull_message_processor.rs`.

# Extract the complete implementation of `is_broadcast`.
rg --type rust --context 30 'fn is_broadcast' rocketmq-broker/src/processor/pull_message_processor.rs

Length of output: 1539

None => proxy_pull_broadcast,
}
}
pub async fn execute_request_when_wakeup(&self, channel: Channel, request: RemotingCommand) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Empty function detected.

The execute_request_when_wakeup function is currently empty. Consider implementing the function or adding a TODO comment.

Do you want me to help implement this function or open a GitHub issue to track this task?

Copy link

codecov bot commented Jun 30, 2024

Codecov Report

Attention: Patch coverage is 0% with 108 lines in your changes missing coverage. Please review.

Project coverage is 27.17%. Comparing base (a2715c2) to head (501b64f).
Report is 1 commits behind head on main.

Files Patch % Lines
rocketmq-broker/src/long_polling/pull_request.rs 0.00% 35 Missing ⚠️
...ketmq-broker/src/long_polling/many_pull_request.rs 0.00% 24 Missing ⚠️
rocketmq-remoting/src/protocol.rs 0.00% 21 Missing ⚠️
...c/processor/default_pull_message_result_handler.rs 0.00% 13 Missing ⚠️
rocketmq-remoting/src/protocol/remoting_command.rs 0.00% 7 Missing ⚠️
.../long_polling_service/pull_request_hold_service.rs 0.00% 3 Missing ⚠️
rocketmq-common/src/common/broker/broker_config.rs 0.00% 2 Missing ⚠️
...src/protocol/header/pull_message_request_header.rs 0.00% 2 Missing ⚠️
...tmq-broker/src/processor/pull_message_processor.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #721      +/-   ##
==========================================
- Coverage   27.29%   27.17%   -0.13%     
==========================================
  Files         262      264       +2     
  Lines       20645    20740      +95     
==========================================
  Hits         5636     5636              
- Misses      15009    15104      +95     

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

@mxsm
Copy link
Owner Author

mxsm commented Jun 30, 2024

🚀Thanks for your contribution🎉. CodeRabbit(AI) will review your code first🔥

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.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 30270ca and 501b64f.

Files selected for processing (4)
  • rocketmq-broker/src/long_polling/long_polling_service/pull_request_hold_service.rs (1 hunks)
  • rocketmq-broker/src/processor/default_pull_message_result_handler.rs (2 hunks)
  • rocketmq-broker/src/processor/pull_message_processor.rs (2 hunks)
  • rocketmq-remoting/src/protocol/remoting_command.rs (3 hunks)
Files skipped from review as they are similar to previous changes (4)
  • rocketmq-broker/src/long_polling/long_polling_service/pull_request_hold_service.rs
  • rocketmq-broker/src/processor/default_pull_message_result_handler.rs
  • rocketmq-broker/src/processor/pull_message_processor.rs
  • rocketmq-remoting/src/protocol/remoting_command.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved PR has approved auto merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Support pull message result handle-3
2 participants