-
Notifications
You must be signed in to change notification settings - Fork 112
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 #1364]🍻Broker Supports request code SetMessageRequestMode (401) #1365
Conversation
WalkthroughThe pull request introduces significant updates to the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
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 #1365 +/- ##
==========================================
- Coverage 21.04% 21.03% -0.01%
==========================================
Files 434 434
Lines 55171 55191 +20
==========================================
Hits 11611 11611
- Misses 43560 43580 +20 ☔ 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: 1
🧹 Outside diff range and nitpick comments (1)
rocketmq-broker/src/processor/query_assignment_processor.rs (1)
101-108
: Use precise response code for invalid topicReturning
NoPermission
may not accurately reflect the issue when a retry topic is not allowed. Consider using a more specific response code likeTopicNotAllowed
orBadRequest
if available.Implementing a more precise response code enhances clarity for the client about why the request was rejected.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
rocketmq-broker/src/processor/query_assignment_processor.rs
(2 hunks)
🔇 Additional comments (3)
rocketmq-broker/src/processor/query_assignment_processor.rs (3)
30-33
: Necessary imports added for new functionality
The additional use
statements are appropriate and required for the implemented changes in the set_message_request_mode
method.
109-114
: Ensure thread-safe access to shared resources
The message_request_mode_manager
is being modified and persisted. If multiple threads can access this method concurrently, there might be race conditions.
Verify that message_request_mode_manager
is protected with synchronization primitives like Mutex
or RwLock
to ensure thread safety.
115-117
: Confirm appropriate success response
Returning ResponseCode::Success
after persisting changes is appropriate. Ensure that this aligns with the client's expectations and the overall protocol design.
request: RemotingCommand, | ||
) -> Option<RemotingCommand> { | ||
unimplemented!() | ||
let request_body = | ||
SetMessageRequestModeRequestBody::decode(request.get_body().expect("empty body")) | ||
.expect("decode SetMessageRequestModeRequestBody failed"); | ||
if request_body.topic.starts_with(RETRY_GROUP_TOPIC_PREFIX) { | ||
return Some( | ||
RemotingCommand::create_response_command_with_code(ResponseCode::NoPermission) | ||
.set_remark(CheetahString::from_static_str( | ||
"retry topic is not allowed to set mode", | ||
)), | ||
); | ||
} | ||
self.message_request_mode_manager.set_message_request_mode( | ||
request_body.topic.clone(), | ||
request_body.consumer_group.clone(), | ||
request_body, | ||
); | ||
self.message_request_mode_manager.persist(); | ||
Some(RemotingCommand::create_response_command_with_code( | ||
ResponseCode::Success, | ||
)) |
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.
Handle potential errors without panicking
Using .expect()
for error handling can cause the program to panic if an error occurs. It's better to handle errors gracefully and return an appropriate response to the client.
Apply the following changes to handle errors more gracefully:
async fn set_message_request_mode(
&mut self,
_channel: Channel,
_ctx: ConnectionHandlerContext,
request: RemotingCommand,
) -> Option<RemotingCommand> {
- let request_body =
- SetMessageRequestModeRequestBody::decode(request.get_body().expect("empty body"))
- .expect("decode SetMessageRequestModeRequestBody failed");
+ let request_body = match request.get_body() {
+ Some(body) => match SetMessageRequestModeRequestBody::decode(body) {
+ Ok(decoded_body) => decoded_body,
+ Err(_) => {
+ return Some(
+ RemotingCommand::create_response_command_with_code(ResponseCode::BadRequest)
+ .set_remark(CheetahString::from_static_str("Failed to decode request body")),
+ );
+ }
+ },
+ None => {
+ return Some(
+ RemotingCommand::create_response_command_with_code(ResponseCode::BadRequest)
+ .set_remark(CheetahString::from_static_str("Empty request body")),
+ );
+ }
+ };
This modification ensures that decoding errors are handled appropriately, and informative responses are sent back to the client without causing a panic.
📝 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.
request: RemotingCommand, | |
) -> Option<RemotingCommand> { | |
unimplemented!() | |
let request_body = | |
SetMessageRequestModeRequestBody::decode(request.get_body().expect("empty body")) | |
.expect("decode SetMessageRequestModeRequestBody failed"); | |
if request_body.topic.starts_with(RETRY_GROUP_TOPIC_PREFIX) { | |
return Some( | |
RemotingCommand::create_response_command_with_code(ResponseCode::NoPermission) | |
.set_remark(CheetahString::from_static_str( | |
"retry topic is not allowed to set mode", | |
)), | |
); | |
} | |
self.message_request_mode_manager.set_message_request_mode( | |
request_body.topic.clone(), | |
request_body.consumer_group.clone(), | |
request_body, | |
); | |
self.message_request_mode_manager.persist(); | |
Some(RemotingCommand::create_response_command_with_code( | |
ResponseCode::Success, | |
)) | |
request: RemotingCommand, | |
) -> Option<RemotingCommand> { | |
let request_body = match request.get_body() { | |
Some(body) => match SetMessageRequestModeRequestBody::decode(body) { | |
Ok(decoded_body) => decoded_body, | |
Err(_) => { | |
return Some( | |
RemotingCommand::create_response_command_with_code(ResponseCode::BadRequest) | |
.set_remark(CheetahString::from_static_str("Failed to decode request body")), | |
); | |
} | |
}, | |
None => { | |
return Some( | |
RemotingCommand::create_response_command_with_code(ResponseCode::BadRequest) | |
.set_remark(CheetahString::from_static_str("Empty request body")), | |
); | |
} | |
}; | |
if request_body.topic.starts_with(RETRY_GROUP_TOPIC_PREFIX) { | |
return Some( | |
RemotingCommand::create_response_command_with_code(ResponseCode::NoPermission) | |
.set_remark(CheetahString::from_static_str( | |
"retry topic is not allowed to set mode", | |
)), | |
); | |
} | |
self.message_request_mode_manager.set_message_request_mode( | |
request_body.topic.clone(), | |
request_body.consumer_group.clone(), | |
request_body, | |
); | |
self.message_request_mode_manager.persist(); | |
Some(RemotingCommand::create_response_command_with_code( | |
ResponseCode::Success, | |
)) |
Which Issue(s) This PR Fixes(Closes)
Fixes #1364
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
Bug Fixes