-
Notifications
You must be signed in to change notification settings - Fork 119
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 #1709]🚀Implement BrokerOuterAPI#send_message_to_specific_broker logic🔥 #1712
Conversation
WalkthroughThe changes in this pull request involve modifications to the message sending logic within the RocketMQ broker. Key updates include enhancements to the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1712 +/- ##
==========================================
- Coverage 27.96% 27.90% -0.06%
==========================================
Files 473 473
Lines 63702 63838 +136
==========================================
Hits 17816 17816
- Misses 45886 46022 +136 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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/out_api/broker_outer_api.rs (1)
470-475
: Update documentation forsend_message_to_specific_broker
methodThe method signature of
send_message_to_specific_broker
has changed by addingbroker_name
and updating parameter names. Ensure that the documentation and comments reflect these changes for clarity.rocketmq-broker/src/failover/escape_bridge.rs (1)
Line range hint
192-199
: HandleNone
case forbroker_name_to_send
more explicitlyWhile
broker_name_to_send
is checked foris_some()
earlier, usingunwrap()
can still lead to panics if the state changes unexpectedly. Consider using pattern matching to handle theNone
case explicitly.Modify the code to safely handle
broker_name_to_send
:- broker_name_to_send.as_ref().unwrap(), + match broker_name_to_send.as_ref() { + Some(broker_name) => broker_name, + None => { + warn!("Broker name to send is None"); + return None; + } + },
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
rocketmq-broker/src/failover/escape_bridge.rs
(1 hunks)rocketmq-broker/src/out_api/broker_outer_api.rs
(4 hunks)rocketmq-remoting/src/protocol/header/message_operation_header/send_message_request_header_v2.rs
(1 hunks)
🔇 Additional comments (3)
rocketmq-broker/src/out_api/broker_outer_api.rs (1)
476-479
: Handle potential None
value for uniq_msg_id
uniq_msg_id
is obtained using MessageClientIDSetter::get_uniq_id(&msg)
, which may return None
. Ensure that using unwrap_or_default()
does not introduce ambiguity if the default unique ID is an empty string.
Run the following script to check for any usage of empty uniq_msg_id
in the codebase:
rocketmq-remoting/src/protocol/header/message_operation_header/send_message_request_header_v2.rs (2)
361-363
: Possible inconsistency in setting n
field
In the create_send_message_request_header_v2_with_move
method, the n
field is set using v1.topic_request_header.as_ref().and_then(|v| v.get_broker_name().cloned())
. Ensure that this correctly retrieves the broker name and handles cases where topic_request_header
or broker_name
might be None
.
Confirm that broker_name
is correctly extracted and that there are no cases where it could be unintentionally None
.
342-365
: Ensure all fields are correctly moved in create_send_message_request_header_v2_with_move
The method create_send_message_request_header_v2_with_move
should transfer all fields from SendMessageRequestHeader
to SendMessageRequestHeaderV2
. Verify that no fields are missed or incorrectly assigned.
Run the following script to compare the fields of both structs and ensure they are all accounted for:
✅ Verification successful
All fields are correctly mapped in the conversion method
Based on the struct definitions and field mappings:
- All fields from
SendMessageRequestHeader
are properly moved to their corresponding fields inSendMessageRequestHeaderV2
- The mapping follows a documented pattern where each field in V2 (a through n) corresponds to a specific field from V1, as shown in the comments
- The types match between source and destination fields
- The optional fields are preserved with their correct optionality
- The additional
topic_request_header
field is correctly handled by extracting the broker name into fieldn
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Compare fields of SendMessageRequestHeader and SendMessageRequestHeaderV2
# Extract fields from both structs
grep -E 'pub (.+?):' rocketmq-remoting/src/protocol/header/message_operation_header/send_message_request_header.rs | sed 's/pub //;s/:.*//' > header_fields.txt
grep -E 'pub (.+?):' rocketmq-remoting/src/protocol/header/message_operation_header/send_message_request_header_v2.rs | sed 's/pub //;s/:.*//' > header_v2_fields.txt
# Compare the fields
diff header_fields.txt header_v2_fields.txt
Length of output: 1079
Script:
#!/bin/bash
# Let's examine the struct definitions and field mappings more clearly
echo "=== SendMessageRequestHeader struct definition ==="
rg -A 15 "pub struct SendMessageRequestHeader" rocketmq-remoting/src/protocol/header/message_operation_header/send_message_request_header.rs
echo -e "\n=== SendMessageRequestHeaderV2 struct definition ==="
rg -A 15 "pub struct SendMessageRequestHeaderV2" rocketmq-remoting/src/protocol/header/message_operation_header/send_message_request_header_v2.rs
echo -e "\n=== Field mappings in create_send_message_request_header_v2_with_move ==="
rg -A 20 "create_send_message_request_header_v2_with_move" rocketmq-remoting/src/protocol/header/message_operation_header/send_message_request_header_v2.rs
Length of output: 2576
Script:
#!/bin/bash
# Let's check the complete SendMessageRequestHeader struct definition to ensure we see all fields
echo "=== Complete SendMessageRequestHeader struct definition ==="
rg -A 30 "pub struct SendMessageRequestHeader" rocketmq-remoting/src/protocol/header/message_operation_header/send_message_request_header.rs
# Also check if there are any comments in SendMessageRequestHeaderV2 that might explain field mappings
echo -e "\n=== SendMessageRequestHeaderV2 field documentation ==="
rg -B 1 "pub [a-z]:" rocketmq-remoting/src/protocol/header/message_operation_header/send_message_request_header_v2.rs
Length of output: 1855
if let Some(trace_on) = | ||
response | ||
.get_ext_fields() | ||
.unwrap() | ||
.get(&CheetahString::from_static_str( | ||
MessageConst::PROPERTY_MSG_REGION, | ||
)) | ||
{ | ||
send_result.set_trace_on(trace_on == "true"); | ||
} else { | ||
send_result.set_trace_on(false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect property key used for setting trace_on
The property key used to retrieve the trace_on
value should be MessageConst::PROPERTY_TRACE_ON
instead of MessageConst::PROPERTY_MSG_REGION
.
Apply the following diff to fix the property key:
-if let Some(trace_on) =
- response
- .get_ext_fields()
- .unwrap()
- .get(&CheetahString::from_static_str(
- MessageConst::PROPERTY_MSG_REGION,
- ))
+if let Some(ext_fields) = response.get_ext_fields() {
+ if let Some(trace_on) = ext_fields.get(&CheetahString::from_static_str(
+ MessageConst::PROPERTY_TRACE_ON,
+ )) {
+ send_result.set_trace_on(trace_on == "true");
+ } else {
+ send_result.set_trace_on(false);
+ }
+} else {
+ send_result.set_trace_on(false);
+}
📝 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.
if let Some(trace_on) = | |
response | |
.get_ext_fields() | |
.unwrap() | |
.get(&CheetahString::from_static_str( | |
MessageConst::PROPERTY_MSG_REGION, | |
)) | |
{ | |
send_result.set_trace_on(trace_on == "true"); | |
} else { | |
send_result.set_trace_on(false); | |
} | |
if let Some(ext_fields) = response.get_ext_fields() { | |
if let Some(trace_on) = ext_fields.get(&CheetahString::from_static_str( | |
MessageConst::PROPERTY_TRACE_ON, | |
)) { | |
send_result.set_trace_on(trace_on == "true"); | |
} else { | |
send_result.set_trace_on(false); | |
} | |
} else { | |
send_result.set_trace_on(false); | |
} |
response | ||
.get_ext_fields() | ||
.unwrap() | ||
.get(&CheetahString::from_static_str( | ||
MessageConst::PROPERTY_MSG_REGION, | ||
)) | ||
{ | ||
send_result.set_region_id(region_id.to_string()); | ||
} else { | ||
send_result.set_region_id(mix_all::DEFAULT_TRACE_REGION_ID.to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid using unwrap()
on get_ext_fields()
to prevent potential panics
Using unwrap()
on response.get_ext_fields()
can cause a panic if ext_fields
is None
. It's safer to handle the None
case explicitly.
Consider modifying the code to handle the None
case safely:
-if let Some(region_id) =
- response
- .get_ext_fields()
- .unwrap()
- .get(&CheetahString::from_static_str(
- MessageConst::PROPERTY_MSG_REGION,
- ))
+if let Some(ext_fields) = response.get_ext_fields() {
+ if let Some(region_id) = ext_fields.get(&CheetahString::from_static_str(
+ MessageConst::PROPERTY_MSG_REGION,
+ )) {
+ send_result.set_region_id(region_id.to_string());
+ } else {
+ send_result.set_region_id(mix_all::DEFAULT_TRACE_REGION_ID.to_string());
+ }
+} else {
+ send_result.set_region_id(mix_all::DEFAULT_TRACE_REGION_ID.to_string());
+}
📝 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.
response | |
.get_ext_fields() | |
.unwrap() | |
.get(&CheetahString::from_static_str( | |
MessageConst::PROPERTY_MSG_REGION, | |
)) | |
{ | |
send_result.set_region_id(region_id.to_string()); | |
} else { | |
send_result.set_region_id(mix_all::DEFAULT_TRACE_REGION_ID.to_string()); | |
if let Some(ext_fields) = response.get_ext_fields() { | |
if let Some(region_id) = ext_fields.get(&CheetahString::from_static_str( | |
MessageConst::PROPERTY_MSG_REGION, | |
)) { | |
send_result.set_region_id(region_id.to_string()); | |
} else { | |
send_result.set_region_id(mix_all::DEFAULT_TRACE_REGION_ID.to_string()); | |
} | |
} else { | |
send_result.set_region_id(mix_all::DEFAULT_TRACE_REGION_ID.to_string()); | |
} |
Which Issue(s) This PR Fixes(Closes)
Fixes #1709
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
Bug Fixes
Documentation