-
Notifications
You must be signed in to change notification settings - Fork 113
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 #1303]🚀Add QueryAssignmentRequestBody and QueryAssignmentResponseBody #1304
Conversation
WalkthroughThe pull request introduces several enhancements to the RocketMQ Rust project, primarily focusing on the addition of new modules and structures related to message queue assignments. Key changes include the creation of the Changes
Assessment against linked issues
Possibly related 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 🔥 |
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 (6)
rocketmq-remoting/src/protocol/body/query_assignment_response_body.rs (1)
23-27
: Add documentation comments to improve API clarity.The struct lacks documentation comments explaining its purpose, usage, and any constraints. Consider adding documentation to help API consumers.
Apply this diff to add documentation:
+/// Response body for message queue assignment queries. +/// +/// This struct represents the response containing a set of message queue assignments +/// returned by the server. Each assignment in the set is unique and represents +/// a specific message queue configuration. #[derive(Debug, Clone, Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub struct QueryAssignmentResponseBody { + /// The set of unique message queue assignments. pub message_queue_assignments: HashSet<MessageQueueAssignment>, }rocketmq-common/src/common/message/message_queue_assignment.rs (3)
28-34
: Add documentation comments to improve code clarity.The struct and its fields lack documentation comments explaining their purpose and usage. Consider adding rustdoc comments to improve code maintainability.
Example improvement:
+/// Represents an assignment of a message queue with its operational mode and metadata. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct MessageQueueAssignment { + /// The optional message queue that is being assigned. pub message_queue: Option<MessageQueue>, + /// The mode of operation for this queue assignment. pub mode: MessageRequestMode, + /// Optional metadata associated with this assignment. pub attachments: Option<HashMap<CheetahString, CheetahString>>, }
49-57
: Document the Default implementation rationale.Add documentation explaining:
- Why Pull is chosen as the default mode
- When this default implementation should be used
Example improvement:
+/// Provides a default configuration for message queue assignment. +/// Uses Pull mode by default as it's the most common use case. impl Default for MessageQueueAssignment { fn default() -> Self { MessageQueueAssignment { message_queue: None, mode: MessageRequestMode::Pull, attachments: None, } } }
1-57
: Consider broader feature integration aspects.As this struct is part of the QueryAssignment feature (#1303), consider:
- Adding integration tests demonstrating the interaction with QueryAssignmentRequestBody and QueryAssignmentResponseBody
- Documenting the relationship between these components
- Providing usage examples in the module-level documentation
rocketmq-common/src/common/message/message_enum.rs (2)
59-59
: Add documentation for MessageRequestMode enumWhile the added traits are appropriate, the enum lacks documentation explaining its purpose and when to use each variant. Consider adding documentation comments to improve code maintainability.
Example improvement:
+/// Represents the mode of message request in RocketMQ. +/// +/// # Variants +/// +/// * `Pull` - Used for pull-based message consumption +/// * `Pop` - Used for pop-based message consumption #[derive(Debug, PartialEq, Copy, Clone, Hash, Eq)] pub enum MessageRequestMode { Pull, Pop, }
163-196
: Consider adding more edge case testsWhile the current test coverage is good, consider adding tests for additional edge cases:
- Deserializing malformed JSON (e.g.,
{
)- Deserializing wrong types (e.g., numbers or objects instead of strings)
Example additional test:
#[test] fn deserialize_message_request_mode_malformed() { let json = "{"; // Malformed JSON let deserialized: Result<MessageRequestMode, _> = serde_json::from_str(json); assert!(deserialized.is_err()); let json = "42"; // Wrong type let deserialized: Result<MessageRequestMode, _> = serde_json::from_str(json); assert!(deserialized.is_err()); }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (6)
rocketmq-common/src/common/message.rs
(1 hunks)rocketmq-common/src/common/message/message_enum.rs
(4 hunks)rocketmq-common/src/common/message/message_queue_assignment.rs
(1 hunks)rocketmq-remoting/src/protocol/body.rs
(1 hunks)rocketmq-remoting/src/protocol/body/query_assignment_request_body.rs
(1 hunks)rocketmq-remoting/src/protocol/body/query_assignment_response_body.rs
(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- rocketmq-common/src/common/message.rs
- rocketmq-remoting/src/protocol/body.rs
🔇 Additional comments (8)
rocketmq-remoting/src/protocol/body/query_assignment_response_body.rs (2)
1-22
: LGTM! Well-structured imports and proper licensing.
The license header is complete, and the imports are well-organized. Using HashSet
for message queue assignments is a good choice as it ensures uniqueness.
25-27
: Consider adding size constraints and validation.
The HashSet
field has no size constraints, which could potentially lead to memory issues with large responses. Consider implementing size validation or using a bounded collection.
Let's check if there are any size constraints in similar response bodies:
rocketmq-remoting/src/protocol/body/query_assignment_request_body.rs (2)
1-20
: LGTM! Proper license header and essential imports.
The file includes the correct ASF license header and necessary imports for serialization functionality.
21-22
: Verify MessageModel usage context
The use of MessageModel
from the heartbeat module needs verification to ensure it's the appropriate type for assignment queries.
✅ Verification successful
Based on the shell script results, I can now generate the final response:
MessageModel usage is appropriate for assignment queries
The MessageModel
enum from the heartbeat module is correctly used in QueryAssignmentRequestBody
as it represents the same message consumption model (Broadcasting/Clustering) that's used throughout the codebase for consumer group configurations and message distribution strategies. This is evidenced by:
- The enum is consistently used across consumer implementations and broker processors
- It's a core part of the consumer group configuration and rebalancing logic
- The same model types (Broadcasting/Clustering) are used for both assignment queries and actual message consumption
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check the MessageModel definition and its usage context
# Check MessageModel definition
ast-grep --pattern 'enum MessageModel { $$$ }'
# Check other usages of MessageModel in similar contexts
rg -A 5 "MessageModel" --type rust
Length of output: 50693
rocketmq-common/src/common/message/message_queue_assignment.rs (2)
1-27
: LGTM! Well-organized imports and proper license header.
The code follows good practices with:
- Proper Apache 2.0 license header
- Logically grouped imports (std, external, internal)
36-47
: Consider HashMap ordering impact on hash consistency.
The current Hash implementation might produce different hashes for equivalent MessageQueueAssignment instances due to non-deterministic HashMap iteration order. This could cause issues in hash-based collections.
Let's verify if there are any hash-dependent uses:
Consider using BTreeMap for deterministic ordering:
- pub attachments: Option<HashMap<CheetahString, CheetahString>>,
+ pub attachments: Option<BTreeMap<CheetahString, CheetahString>>,
rocketmq-common/src/common/message/message_enum.rs (2)
17-24
: LGTM: Clean import organization
The new imports are well-organized and properly support the added serialization functionality.
74-114
: LGTM: Well-implemented serialization
The serialization and deserialization implementations are robust and follow Rust best practices:
- Proper use of the Visitor pattern
- Consistent string representations
- Good error handling with helpful messages
#[derive(Debug, Clone, Serialize, Deserialize, Default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct QueryAssignmentRequestBody { | ||
pub topic: CheetahString, | ||
pub consumer_group: CheetahString, | ||
pub client_id: CheetahString, | ||
pub strategy_name: CheetahString, | ||
pub message_model: MessageModel, | ||
} |
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
Add documentation and consider implementing additional functionality
The structure definition needs the following improvements:
- Add documentation comments (rustdoc) for the structure and its fields
- Consider adding field validation
- Consider implementing additional traits or methods if needed
Add documentation like this:
+/// Request body for querying message queue assignments
+///
+/// This structure is used in the RocketMQ protocol to request assignment information
+/// for a specific topic and consumer group combination.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct QueryAssignmentRequestBody {
+ /// The topic name for which assignments are being queried
pub topic: CheetahString,
+ /// The consumer group requesting the assignments
pub consumer_group: CheetahString,
+ /// Unique identifier of the client making the request
pub client_id: CheetahString,
+ /// Name of the assignment strategy to be used
pub strategy_name: CheetahString,
+ /// Message model type for the assignments
pub message_model: MessageModel,
}
Consider adding unit tests:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_query_assignment_request_body_serialization() {
// Add serialization/deserialization tests
}
}
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
use cheetah_string::CheetahString; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
use crate::protocol::heartbeat::message_model::MessageModel; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, Default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct QueryAssignmentRequestBody { | ||
pub topic: CheetahString, | ||
pub consumer_group: CheetahString, | ||
pub client_id: CheetahString, | ||
pub strategy_name: CheetahString, | ||
pub message_model: MessageModel, | ||
} |
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.
💡 Codebase verification
Request and response bodies are properly structured but processor implementation is incomplete
The QueryAssignmentRequestBody and QueryAssignmentResponseBody are well-defined, but the processor implementation in rocketmq-broker/src/processor/query_assignment_processor.rs
is incomplete with a todo!()
macro. This needs to be implemented before the feature can be used.
rocketmq-broker/src/processor/query_assignment_processor.rs
: Processor implementation is a stub withtodo!()
rocketmq-remoting/src/code/request_code.rs
: Request code 400 is properly registered for QueryAssignmentrocketmq-remoting/src/protocol/body/query_assignment_request_body.rs
: Request body structure is completerocketmq-remoting/src/protocol/body/query_assignment_response_body.rs
: Response body structure is complete
🔗 Analysis chain
Verify integration with QueryAssignmentResponseBody
This request body should have a corresponding response body structure and proper integration points.
Let me check the response body implementation to ensure proper integration.
Let me check one more thing to verify if these types are properly integrated into the protocol/command system.
Let me check one final thing to verify the query assignment processor implementation.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the complete query assignment feature implementation
# Find the corresponding response body
fd -e rs "query_assignment_response_body"
# Check for handler/processor implementations
rg -l "QueryAssignmentRequestBody|QueryAssignmentResponseBody" --type rust
# Look for test files covering this functionality
fd -e rs "test.*query.*assignment"
Length of output: 364
Script:
#!/bin/bash
# Check the response body implementation
cat rocketmq-remoting/src/protocol/body/query_assignment_response_body.rs
# Check if these types are used in any request/response handling code
rg -A 5 "QueryAssignmentRequestBody|QueryAssignmentResponseBody" --type rust
Length of output: 2282
Script:
#!/bin/bash
# Check for command code and request/response type registration
rg -l "RemotingCommand|RequestCode" --type rust
# Then check the content of potential command registration files
ast-grep --pattern 'RequestCode::$_'
Length of output: 31228
Script:
#!/bin/bash
# Check the query assignment processor implementation
cat rocketmq-broker/src/processor/query_assignment_processor.rs
# Check if QueryAssignment request code is properly registered
rg -A 5 "RequestCode::QueryAssignment" --type rust
Length of output: 1907
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1304 +/- ##
==========================================
+ Coverage 18.97% 19.04% +0.06%
==========================================
Files 428 431 +3
Lines 53868 53939 +71
==========================================
+ Hits 10224 10272 +48
- Misses 43644 43667 +23 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
Which Issue(s) This PR Fixes(Closes)
Fixes #1303
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
Enhancements
MessageRequestMode
enum with serialization and deserialization capabilities for improved data interchange.Bug Fixes
MessageRequestMode
.Tests