-
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 #1907]🚨Add PollingHeader struct for rust🚀 #1912
Conversation
WalkthroughThe pull request introduces a new module 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🔥! Note 🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1912 +/- ##
==========================================
+ Coverage 28.46% 28.59% +0.13%
==========================================
Files 478 479 +1
Lines 67372 67497 +125
==========================================
+ Hits 19175 19300 +125
Misses 48197 48197 ☔ 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
🧹 Nitpick comments (2)
rocketmq-broker/src/long_polling/polling_header.rs (2)
23-30
: Add documentation for the struct and its fields.Consider adding rustdoc comments to document:
- The purpose and usage of the
PollingHeader
struct- The meaning and expected values of each field
- Any invariants or constraints that should be maintained
Example documentation:
/// Represents a polling header for RocketMQ's long polling mechanism. /// /// This struct encapsulates the necessary information to identify and track /// a polling request from a consumer. #[derive(Clone, Debug)] pub struct PollingHeader { /// The group identifier of the consumer consumer_group: CheetahString, /// The topic being polled topic: CheetahString, /// The queue identifier within the topic queue_id: i32, /// Timestamp when the polling request was created born_time: i64, /// Timestamp when the actual polling occurred poll_time: i64, }
86-184
: Add tests for edge cases and error scenarios.While the current test coverage is good, consider adding tests for:
- Edge cases:
- Maximum/minimum values for queue_id
- Extreme timestamp values
- Empty strings for consumer_group and topic
- Error scenarios (after implementing validation):
- Negative timestamps
- Invalid queue_id values
Example additional test:
#[test] fn polling_header_edge_cases() { let header = PollingHeader { consumer_group: CheetahString::from(""), topic: CheetahString::from(""), queue_id: i32::MAX, born_time: i64::MAX, poll_time: i64::MIN, }; assert_eq!(header.get_consumer_group().len(), 0); assert_eq!(header.get_topic().len(), 0); assert_eq!(header.get_queue_id(), i32::MAX); assert_eq!(header.get_born_time(), i64::MAX); assert_eq!(header.get_poll_time(), i64::MIN); }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
rocketmq-broker/src/long_polling.rs
(1 hunks)rocketmq-broker/src/long_polling/polling_header.rs
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- rocketmq-broker/src/long_polling.rs
🔇 Additional comments (3)
rocketmq-broker/src/long_polling/polling_header.rs (3)
1-22
: LGTM! License and imports are properly structured.
The license header is complete and all imports are necessary for the implementation.
32-40
: LGTM! Display implementation is well-structured.
The Display implementation provides a clear and complete string representation of the struct.
65-84
: LGTM! Getter methods are properly implemented.
The getters follow Rust best practices by returning references for string types and values for primitive types.
impl PollingHeader { | ||
pub fn new_from_pop_message_request_header(request_header: &PopMessageRequestHeader) -> Self { | ||
Self { | ||
consumer_group: request_header.consumer_group.clone(), | ||
topic: request_header.topic.clone(), | ||
queue_id: request_header.queue_id, | ||
born_time: request_header.born_time as i64, | ||
poll_time: request_header.poll_time as i64, | ||
} | ||
} | ||
|
||
pub fn new_from_notification_request_header( | ||
request_header: &NotificationRequestHeader, | ||
) -> Self { | ||
Self { | ||
consumer_group: request_header.consumer_group.clone(), | ||
topic: request_header.topic.clone(), | ||
queue_id: request_header.queue_id, | ||
born_time: request_header.born_time, | ||
poll_time: request_header.poll_time, | ||
} | ||
} | ||
|
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
Consider adding input validation and optimizing clones.
Two suggestions for improvement:
- Add validation for the timestamp conversions and field values:
pub fn new_from_pop_message_request_header(request_header: &PopMessageRequestHeader) -> Result<Self, &'static str> {
if request_header.born_time < 0 || request_header.poll_time < 0 {
return Err("Timestamps cannot be negative");
}
Ok(Self {
consumer_group: request_header.consumer_group.clone(),
topic: request_header.topic.clone(),
queue_id: request_header.queue_id,
born_time: request_header.born_time as i64,
poll_time: request_header.poll_time as i64,
})
}
- Consider using references instead of cloning if the lifetime of the header allows it:
pub struct PollingHeader<'a> {
consumer_group: &'a CheetahString,
topic: &'a CheetahString,
// ... other fields
}
Which Issue(s) This PR Fixes(Closes)
Fixes #1907
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
PollingHeader
structure for handling polling header information.PollingHeader
instances from various request headers.PollingHeader
.Tests
PollingHeader
struct and its methods.