Skip to content

[ISSUE #1527]⚡️Optimize SendMessageProcessor handle error logic #1528

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

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Dec 3, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #1527

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for message sending operations, providing more detailed feedback on failures.
  • Bug Fixes

    • Improved the robustness of message processing logic, ensuring better handling of asynchronous operations.
  • Refactor

    • Simplified method signatures for sending messages, improving clarity and usability.
    • Updated the topic method to return a reference to a CheetahString, enhancing type handling.

Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

Walkthrough

The changes in this pull request focus on enhancing error handling within the SendMessageProcessor and modifying the return types of several methods. Specifically, the send_message and send_batch_message methods have been updated to return a Result type instead of an Option, allowing for more detailed error reporting. Additionally, the topic method in the MessageExtBrokerInner struct has been altered to return a reference to CheetahString instead of &str. These modifications aim to improve the robustness and clarity of the code.

Changes

File Path Change Summary
rocketmq-broker/src/processor/send_message_processor.rs Updated send_message and send_batch_message methods to return crate::Result<Option<RemotingCommand>>. Modified handle_put_message_result for improved error handling. Simplified process_request method logic. Added import for RemotingCommandError.
rocketmq-common/src/common/message/message_ext_broker_inner.rs Changed return type of topic method from &str to &CheetahString.

Assessment against linked issues

Objective Addressed Explanation
Optimize error handling in SendMessageProcessor (1527)

Possibly related issues

Possibly related PRs

Suggested labels

enhancement, auto merge, ready to review, AI review first

Suggested reviewers

  • TeslaRustor
  • SpaceXCN

Poem

In the code where messages flow,
A rabbit hops, with changes to show.
With error handling now so bright,
Our SendMessage takes flight!
Cheetah strings, oh what a delight,
In the world of Rust, all feels right! 🐇✨


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 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-robot rocketmq-rust-robot added this to the v0.4.0 milestone Dec 3, 2024
@rocketmq-rust-robot rocketmq-rust-robot added the enhancement⚡️ New feature or request label Dec 3, 2024
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 0.58140% with 171 lines in your changes missing coverage. Please review.

Project coverage is 24.86%. Comparing base (2765c40) to head (e38c72d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tmq-broker/src/processor/send_message_processor.rs 0.00% 171 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1528      +/-   ##
==========================================
- Coverage   24.86%   24.86%   -0.01%     
==========================================
  Files         450      450              
  Lines       59494    59506      +12     
==========================================
  Hits        14795    14795              
- Misses      44699    44711      +12     

☔ 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: 2

🧹 Outside diff range and nitpick comments (2)
rocketmq-broker/src/processor/send_message_processor.rs (2)

146-155: Simplify await calls by removing unnecessary Ok() wrapping

The code has been simplified by removing the unnecessary Ok() wrapping around the await calls for the send_message method. This improves code readability and clarity.


158-167: Simplify await calls by removing unnecessary Ok() wrapping

Similarly, the await call for the send_batch_message method no longer wraps the result in Ok(), which enhances readability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2765c40 and e38c72d.

📒 Files selected for processing (2)
  • rocketmq-broker/src/processor/send_message_processor.rs (16 hunks)
  • rocketmq-common/src/common/message/message_ext_broker_inner.rs (1 hunks)
🔇 Additional comments (2)
rocketmq-broker/src/processor/send_message_processor.rs (2)

219-219: Enhance error propagation by updating method return types

Updating the return types of send_batch_message and send_message to crate::Result<Option<RemotingCommand>> allows for better error handling and propagation throughout the code.

Also applies to: 429-429


373-374: Ensure proper error handling of asynchronous tasks

By adding .map_err(|e| RemotingCommandError(e.to_string()))? after the await on the spawned tasks, the code correctly handles errors that may occur during asynchronous execution, ensuring they are propagated appropriately.

Also applies to: 568-569

Comment on lines +632 to +683
rocketmq_store::base::message_status_enum::PutMessageStatus::PutOk => {
send_ok = true;
response.set_code_ref(RemotingSysResponseCode::Success);
},
rocketmq_store::base::message_status_enum::PutMessageStatus::FlushDiskTimeout => {
send_ok = true;
response.set_code_ref(ResponseCode::FlushDiskTimeout);
},
rocketmq_store::base::message_status_enum::PutMessageStatus::FlushSlaveTimeout => {
send_ok = true;
response.set_code_ref(ResponseCode::FlushSlaveTimeout);
},
rocketmq_store::base::message_status_enum::PutMessageStatus::SlaveNotAvailable =>{
send_ok = true;
response.set_code_ref(ResponseCode::SlaveNotAvailable);
},
rocketmq_store::base::message_status_enum::PutMessageStatus::ServiceNotAvailable => {
response.set_code_mut(ResponseCode::ServiceNotAvailable).set_remark_mut("service not available now. It may be caused by one of the following reasons: \
the broker's disk is full %s, messages are put to the slave, message store has been shut down, etc.");
},
rocketmq_store::base::message_status_enum::PutMessageStatus::CreateMappedFileFailed => {
response.set_code_mut(RemotingSysResponseCode::SystemError).set_remark_mut("create mapped file failed, remoting_server is busy or broken.");
},
rocketmq_store::base::message_status_enum::PutMessageStatus::MessageIllegal |
rocketmq_store::base::message_status_enum::PutMessageStatus::PropertiesSizeExceeded => {
response.set_code_mut(ResponseCode::MessageIllegal).set_remark_mut("the message is illegal, maybe msg body or properties length not matched. msg body length limit B, msg properties length limit 32KB.");
},
rocketmq_store::base::message_status_enum::PutMessageStatus::OsPageCacheBusy =>{
response.set_code_mut(RemotingSysResponseCode::SystemError).set_remark_mut("[PC_SYNCHRONIZED]broker busy, start flow control for a while");
},
rocketmq_store::base::message_status_enum::PutMessageStatus::UnknownError => {
response.set_code_mut(RemotingSysResponseCode::SystemError).set_remark_mut("UNKNOWN_ERROR");
},
rocketmq_store::base::message_status_enum::PutMessageStatus::InSyncReplicasNotEnough => {
response.set_code_mut(RemotingSysResponseCode::SystemError).set_remark_mut("in-sync replicas not enough");
},
rocketmq_store::base::message_status_enum::PutMessageStatus::LmqConsumeQueueNumExceeded => {
response.set_code_mut(RemotingSysResponseCode::SystemError).set_remark_mut("[LMQ_CONSUME_QUEUE_NUM_EXCEEDED]broker config enableLmq and enableMultiDispatch, lmq consumeQueue num exceed maxLmqConsumeQueueNum config num, default limit 2w.");
},
rocketmq_store::base::message_status_enum::PutMessageStatus::WheelTimerFlowControl => {
response.set_code_mut(RemotingSysResponseCode::SystemError).set_remark_mut("timer message is under flow control, max num limit is %d or the current value is greater than %d and less than %d, trigger random flow control");
},
rocketmq_store::base::message_status_enum::PutMessageStatus::WheelTimerMsgIllegal => {
response.set_code_mut(ResponseCode::MessageIllegal).set_remark_mut("timer message illegal, the delay time should not be bigger than the max delay %dms; or if set del msg, the delay time should be bigger than the current time");
},
rocketmq_store::base::message_status_enum::PutMessageStatus::WheelTimerNotEnable => {
response.set_code_mut(RemotingSysResponseCode::SystemError).set_remark_mut("accurate timer message is not enabled, timerWheelEnable is %s");
},
_ => {
response.set_code_mut(RemotingSysResponseCode::SystemError).set_remark_mut("UNKNOWN_ERROR DEFAULT");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Inconsistent send_ok flag setting in error handling

In the handle_put_message_result method, the send_ok flag is set to true in some match arms but not in others. This could lead to inconsistent behavior in subsequent logic that relies on send_ok. Please review and ensure that send_ok is set appropriately in all relevant cases.

@@ -62,7 +62,7 @@ impl MessageExtBrokerInner {
self.version
}

pub fn topic(&self) -> &str {
pub fn topic(&self) -> &CheetahString {
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update method return type impacts dependent code

Changing the return type of the topic() method to &CheetahString may affect other parts of the codebase that rely on this method. Ensure all usages of topic() are updated to handle the new return type, preventing potential type mismatch errors.

@rocketmq-rust-bot
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI review first Ai review pr first approved PR has approved auto merge enhancement⚡️ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement⚡️] Optimize SendMessageProcessor handle error logic
4 participants