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 #722]🚀Support pull message result handle-4 #728

Merged
merged 1 commit into from
Jul 2, 2024
Merged

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Jul 2, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #722

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Introduced optional pull_request_hold_service to enhance message processing hold capabilities.
    • Added NO_SUSPEND_KEY constant for improved message handling control.
    • New write method in ConnectionHandlerContextWrapper for asynchronous command handling.
    • Added message_arriving_listener to DefaultMessageStore for enhanced message arrival notifications.
  • Improvements

    • Refactored several methods and modules for better code organization and performance.
    • Enhanced execute_request_when_wakeup function for asynchronous processing.

@github-actions github-actions bot requested a review from SpaceXCN July 2, 2024 08:16
@mxsm
Copy link
Owner Author

mxsm commented Jul 2, 2024

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

Copy link
Contributor

coderabbitai bot commented Jul 2, 2024

Walkthrough

This update introduces a new feature to the RocketMQ Broker, primarily focused on enhancing the handling of pull message results. Key changes include the addition of new imports, updates to the BrokerRuntime struct, introduction of the PullRequestHoldService, and modifications to message handling logic. The feature enriches the broker's capabilities around long-polling, connection handling, and message arriving notifications.

Changes

File Path Change Summary
rocketmq-broker/src/broker_runtime.rs Added imports, modified BrokerRuntime struct, updated init_processor method, and initialized new fields.
rocketmq-broker/src/coldctr/...pull_request_hold_service.rs Added public constant NO_SUSPEND_KEY.
rocketmq-broker/src/long_polling.rs Replaced message_arriving_listener module with notify_message_arriving_listener module.
rocketmq-broker/src/long_polling/.../pull_request_hold_service.rs Added imports, new field to PullRequestHoldService, modified methods, introduced start method.
rocketmq-broker/src/long_polling/notify_message_arriving_listener.rs Updated import path for MessageArrivingListener.
rocketmq-broker/src/long_polling/pull_request.rs Added public method connection_handler_context to PullRequest struct.
rocketmq-broker/src/processor/pull_message_processor.rs Added import for NO_SUSPEND_KEY, modified message_store type, updated execute_request_when_wakeup function.
rocketmq-broker/src/util/hook_utils.rs Removed unused imports and MockMessageStore structure along with its methods and tests.
rocketmq-remoting/src/runtime/server.rs Added asynchronous write method to ConnectionHandlerContextWrapper.
rocketmq-store/src/base.rs Added new module message_arriving_listener.
rocketmq-store/src/log_file.rs Added import and method for notification on message arrival.
rocketmq-store/src/message_store/default_message_store.rs Added message_arriving_listener field to DefaultMessageStore, methods for setting and notifying listeners.

Sequence Diagram(s)

sequenceDiagram
    participant BrokerRuntime
    participant PullRequestHoldService
    participant DefaultMessageStore
    participant Listener
    BrokerRuntime->>PullRequestHoldService: Initialize with BrokerConfig
    PullRequestHoldService->>DefaultMessageStore: Set message_arriving_listener
    BrokerRuntime->>DefaultMessageStore: Notify message arrival
    DefaultMessageStore->>Listener: Message arrival notification
Loading

Assessment against linked issues

Objective (Issue #722) Addressed Explanation
Enhance pull message result handling
Introduce PullRequestHoldService in broker
Modify BrokerRuntime to use new components
Add message arrival listener to DefaultMessageStore

Poem

In code's quiet hum, changes bloom,
Pull requests hold, in the broker's room.
Messages dance, listeners cheer,
RocketMQ's path becomes clear.
With every tweak, a future bright,
CodeRabbit smiles with sheer delight. 🌟


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 currently opted into early access features by default.

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

Commits

Files that changed from the base of the PR and between fae0049 and e6818ff.

Files selected for processing (12)
  • rocketmq-broker/src/broker_runtime.rs (9 hunks)
  • rocketmq-broker/src/coldctr/cold_data_pull_request_hold_service.rs (1 hunks)
  • rocketmq-broker/src/long_polling.rs (1 hunks)
  • rocketmq-broker/src/long_polling/long_polling_service/pull_request_hold_service.rs (8 hunks)
  • rocketmq-broker/src/long_polling/notify_message_arriving_listener.rs (1 hunks)
  • rocketmq-broker/src/long_polling/pull_request.rs (1 hunks)
  • rocketmq-broker/src/processor/pull_message_processor.rs (6 hunks)
  • rocketmq-broker/src/util/hook_utils.rs (1 hunks)
  • rocketmq-remoting/src/runtime/server.rs (1 hunks)
  • rocketmq-store/src/base.rs (1 hunks)
  • rocketmq-store/src/log_file.rs (2 hunks)
  • rocketmq-store/src/message_store/default_message_store.rs (7 hunks)
Files skipped from review due to trivial changes (1)
  • rocketmq-broker/src/util/hook_utils.rs
Additional comments not posted (29)
rocketmq-broker/src/coldctr/cold_data_pull_request_hold_service.rs (1)

17-17: Constant Definition: NO_SUSPEND_KEY

The constant NO_SUSPEND_KEY is appropriately defined and named. Ensure it is used consistently throughout the codebase.

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

Line range hint 8-8: New Module: notify_message_arriving_listener

The new module notify_message_arriving_listener is correctly added. Ensure that all references to the old message_arriving_listener module are updated to use this new module.

rocketmq-store/src/base.rs (1)

27-27: New Module: message_arriving_listener

The new module message_arriving_listener is correctly added. Ensure that it is used appropriately for handling message arrival events.

rocketmq-broker/src/long_polling/notify_message_arriving_listener.rs (4)

19-19: Import Path Update

The import path for MessageArrivingListener has been updated to rocketmq_store::base::message_arriving_listener. Ensure that all references are updated accordingly.


21-21: New Struct: NotifyMessageArrivingListener

The NotifyMessageArrivingListener struct is correctly defined with the pull_request_hold_service field. Ensure that the field is correctly initialized and used.


Line range hint 23-29: Method: new

The new method correctly initializes the NotifyMessageArrivingListener struct with the pull_request_hold_service field.


Line range hint 31-47: Implementation of MessageArrivingListener

The implementation of the MessageArrivingListener trait for NotifyMessageArrivingListener is correct. The arriving method correctly delegates to the notify_message_arriving_ext method of pull_request_hold_service.

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

92-94: LGTM!

The new method connection_handler_context correctly returns a reference to the ctx field.

rocketmq-store/src/log_file.rs (1)

112-112: LGTM!

The new method notify_message_arrive_if_necessary is correctly added to the RocketMQMessageStore trait.

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

Line range hint 40-56: LGTM!

The PullRequestHoldService::new method correctly initializes the broker_config field.


66-89: LGTM!

The PullRequestHoldService::start method correctly implements the polling logic based on the broker_config.


108-108: LGTM!

The check_hold_request method correctly calls notify_message_arriving.


162-162: LGTM!

The notify_message_arriving method correctly calls execute_request_when_wakeup with the new context parameter.


201-201: LGTM!

The notify_master_online method correctly calls execute_request_when_wakeup with the new context parameter.

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

53-53: New Import: NO_SUSPEND_KEY.

The new import NO_SUSPEND_KEY appears to be used in the updated methods.


75-75: Refactor: Use Arc for message_store.

The message_store field is now wrapped in Arc, improving thread safety and shared ownership.


324-324: Refactor: Asynchronous process_request method.

The process_request method has been updated to be asynchronous and now accepts additional parameters including ctx.


788-818: New Method: Asynchronous execute_request_when_wakeup.

The execute_request_when_wakeup method now includes asynchronous processing and uses NO_SUSPEND_KEY.

rocketmq-broker/src/broker_runtime.rs (6)

57-58: New Imports: PullRequestHoldService and NotifyMessageArrivingListener.

The new imports are used for handling pull requests and notifying message arrivals.


108-109: New Field: pull_request_hold_service.

The BrokerRuntime struct now includes an optional pull_request_hold_service field, which is initialized and used within the struct's implementation.


141-141: Clone Implementation: pull_request_hold_service.

The pull_request_hold_service field is correctly cloned in the Clone implementation of BrokerRuntime.


215-215: Initialization: pull_request_hold_service.

The pull_request_hold_service field is correctly initialized to None in the new method.


Line range hint 364-407: Initialization: pull_request_hold_service and message_arriving_listener.

The init_processor method correctly initializes pull_request_hold_service and sets message_arriving_listener.


598-600: Start pull_request_hold_service.

The pull_request_hold_service is correctly started if it is initialized.

rocketmq-store/src/message_store/default_message_store.rs (5)

59-59: Import Addition Approved.

The import of MessageArrivingListener is necessary for the new functionality.


111-112: Field Addition Approved.

The addition of the message_arriving_listener field and its inclusion in the Clone implementation and new method is necessary to support the new functionality for handling pull message results.

Also applies to: 139-139, 216-216


454-461: Method Addition Approved.

The set_message_arriving_listener method allows setting the listener for message arrivals, which is necessary for the new functionality.


975-989: Method Addition Approved.

The notify_message_arrive_if_necessary method handles the message arrival notifications, which is necessary for the new functionality.


1015-1017: Method Addition Approved.

The notify_message_arrive4multi_queue method is necessary for the new functionality.

Comment on lines +362 to +369
pub async fn write(&mut self, cmd: RemotingCommand) {
match self.connection.framed.send(cmd).await {
Ok(_) => {}
Err(error) => {
error!("send response failed: {}", error);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling in write method.

The write method logs an error if sending the response fails but does not handle the error beyond logging. Consider adding error handling logic to ensure robustness.

pub async fn write(&mut self, cmd: RemotingCommand) -> Result<(), Box<dyn std::error::Error>> {
    match self.connection.framed.send(cmd).await {
        Ok(_) => Ok(()),
        Err(error) => {
            error!("send response failed: {}", error);
            Err(Box::new(error))
        }
    }
}

Copy link

codecov bot commented Jul 2, 2024

Codecov Report

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

Project coverage is 26.86%. Comparing base (fae0049) to head (e6818ff).

Files Patch % Lines
...tmq-broker/src/processor/pull_message_processor.rs 0.00% 25 Missing ⚠️
.../long_polling_service/pull_request_hold_service.rs 0.00% 21 Missing ⚠️
...q-store/src/message_store/default_message_store.rs 0.00% 20 Missing ⚠️
rocketmq-broker/src/broker_runtime.rs 0.00% 15 Missing ⚠️
rocketmq-remoting/src/runtime/server.rs 0.00% 7 Missing ⚠️
rocketmq-broker/src/long_polling/pull_request.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #728      +/-   ##
==========================================
- Coverage   27.15%   26.86%   -0.29%     
==========================================
  Files         263      264       +1     
  Lines       20755    20844      +89     
==========================================
- Hits         5636     5600      -36     
- Misses      15119    15244     +125     

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

@TeslaRustor TeslaRustor added approved PR has approved and removed ready to review labels Jul 2, 2024
@mxsm mxsm merged commit dae0faa into main Jul 2, 2024
15 of 17 checks passed
@mxsm mxsm deleted the feature-722 branch July 2, 2024 08:30
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-4
2 participants