Skip to content

[ISSUE #1699]🚀EscapeBridge supports putMessageToSpecificQueue#1715

Merged
rocketmq-rust-bot merged 1 commit intomainfrom
feature-1699
Dec 11, 2024
Merged

[ISSUE #1699]🚀EscapeBridge supports putMessageToSpecificQueue#1715
rocketmq-rust-bot merged 1 commit intomainfrom
feature-1699

Conversation

@mxsm
Copy link
Copy Markdown
Owner

@mxsm mxsm commented Dec 11, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #1699

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Introduced a new asynchronous method for placing messages in specific queues, enhancing message distribution control.
  • Bug Fixes

    • Improved handling of cases where topic publish information is empty, ensuring robust message processing.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The changes introduce a new asynchronous method put_message_to_specific_queue in the EscapeBridge struct, enhancing message placement capabilities. This method checks the broker's identity and configuration, allowing messages to be sent directly to the message store or to a specific broker based on its role (master or slave). It includes logic for handling empty topic publish information and computes a queue index based on message properties. Additionally, it imports JavaStringHasher for hashing purposes.

Changes

File Path Change Summary
rocketmq-broker/src/failover/escape_bridge.rs Added method put_message_to_specific_queue to EscapeBridge for improved message placement logic.

Assessment against linked issues

Objective Addressed Explanation
Support putMessageToSpecificQueue functionality (1699)

Possibly related issues

Possibly related PRs

Suggested labels

feature, auto merge, ready to review, waiting-review, AI review first

Suggested reviewers

  • SpaceXCN
  • TeslaRustor

Poem

In the land where messages hop,
A new queue method makes them stop.
With a hash and a check, oh so neat,
They find their way, a routing feat!
EscapeBridge now dances with glee,
Sending messages, wild and free! 🐇✨


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. (Experiment)
  • @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 11, 2024
@rocketmq-rust-bot rocketmq-rust-bot added the AI review first Ai review pr first label Dec 11, 2024
@rocketmq-rust-bot
Copy link
Copy Markdown
Collaborator

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

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 11, 2024

Codecov Report

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

Project coverage is 27.86%. Comparing base (809de18) to head (d109ae1).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
rocketmq-broker/src/failover/escape_bridge.rs 0.00% 49 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1715      +/-   ##
==========================================
- Coverage   27.89%   27.86%   -0.03%     
==========================================
  Files         473      473              
  Lines       63879    63928      +49     
==========================================
  Hits        17816    17816              
- Misses      46063    46112      +49     

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

Copy link
Copy Markdown
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 (4)
rocketmq-broker/src/failover/escape_bridge.rs (4)

289-293: Avoid unnecessary string concatenation in id generation

The id variable is created by concatenating topic and store_host, which may be inefficient. Consider using a tuple or struct to represent the combination for hashing purposes.

Optionally, apply this diff to improve efficiency:

-let id = format!(
-    "{}{}",
-    message_ext.get_topic(),
-    message_ext.message_ext_inner.store_host
-);
+let id = (message_ext.get_topic(), &message_ext.message_ext_inner.store_host);
 let code = JavaStringHasher::new().hash(&id);

288-288: Remove commented-out code for cleanliness

There is commented-out code on line 288. Removing such code improves readability and maintainability.

Apply this diff to remove the commented line:

-//let message_queue = mq_selected.unwrap();

303-312: Handle potential errors from send_message_to_specific_broker

The code assumes that send_message_to_specific_broker will succeed. Consider handling possible errors more gracefully, perhaps by logging them or providing more context in failure cases.

Optionally, apply this diff to improve error handling:

 let result = self
     .broker_outer_api
     .send_message_to_specific_broker(
         broker_addr_to_send.as_ref().unwrap(),
         broker_name_to_send,
         message_ext.message_ext_inner,
         producer_group,
         SEND_TIMEOUT,
     )
     .await;
-transform_send_result2put_result(result.ok())
+match result {
+    Ok(send_result) => transform_send_result2put_result(Some(send_result)),
+    Err(e) => {
+        warn!(
+            "Failed to send message to broker {}: {:?}",
+            broker_name_to_send, e
+        );
+        PutMessageResult::new(PutMessageStatus::PutToRemoteBrokerFail, None, true)
+    }
+}

270-274: Simplify the conditional check for readability

The conditional expression can be simplified for better readability by grouping conditions logically.

Apply this diff to simplify the condition:

-} else if self.broker_config.enable_slave_acting_master
-    && self.broker_config.enable_remote_escape
-{
+} else if self.broker_config.enable_slave_acting_master && self.broker_config.enable_remote_escape {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 809de18 and d109ae1.

📒 Files selected for processing (1)
  • rocketmq-broker/src/failover/escape_bridge.rs (2 hunks)

Comment on lines +289 to +295
let id = format!(
"{}{}",
message_ext.get_topic(),
message_ext.message_ext_inner.store_host
);
let code = JavaStringHasher::new().hash_str(id.as_str());
let index = code as usize % topic_publish_info.message_queue_list.len();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle potential negative hash code to prevent index out of bounds

The hash_str function may return a negative value, and casting a negative i32 to usize can lead to a large positive number due to two's complement representation. This can cause index to be out of bounds when accessing message_queue_list. To prevent this, ensure the hash code is non-negative before casting.

Apply this diff to fix the issue:

 let code = JavaStringHasher::new().hash_str(id.as_str());
-let index = code as usize % topic_publish_info.message_queue_list.len();
+let index = (code.abs() as usize) % topic_publish_info.message_queue_list.len();
📝 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
let id = format!(
"{}{}",
message_ext.get_topic(),
message_ext.message_ext_inner.store_host
);
let code = JavaStringHasher::new().hash_str(id.as_str());
let index = code as usize % topic_publish_info.message_queue_list.len();
let id = format!(
"{}{}",
message_ext.get_topic(),
message_ext.message_ext_inner.store_host
);
let code = JavaStringHasher::new().hash_str(id.as_str());
let index = (code.abs() as usize) % topic_publish_info.message_queue_list.len();

Comment on lines +299 to +302
let broker_addr_to_send = self
.topic_route_info_manager
.find_broker_address_in_publish(Some(broker_name_to_send));
let producer_group = self.get_producer_group(&message_ext);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Check for broker_addr_to_send being None to avoid panic

The code calls broker_addr_to_send.as_ref().unwrap() without verifying if broker_addr_to_send is None. This can cause a panic if the broker address is not found. Please add a check for broker_addr_to_send.is_none() and handle the None case appropriately.

Apply this diff to fix the issue:

 let broker_addr_to_send = self
     .topic_route_info_manager
     .find_broker_address_in_publish(Some(broker_name_to_send));
+if broker_addr_to_send.is_none() {
+    warn!(
+        "putMessageToSpecificQueue failed, remote broker not found. Topic: {}, MsgId: {}, Broker: {}",
+        message_ext.get_topic(),
+        message_ext.message_ext_inner.msg_id,
+        broker_name_to_send
+    );
+    return PutMessageResult::new(PutMessageStatus::PutToRemoteBrokerFail, None, true);
+}

Committable suggestion skipped: line range outside the PR's diff.

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 feature🚀 Suggest an idea for this project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature🚀] EscapeBridge supports putMessageToSpecificQueue

4 participants