-
Notifications
You must be signed in to change notification settings - Fork 144
[ISSUE #1763]🚀Implement ConsumerOrderInfoManager#auto_clean method function🔥 #1765
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
Conversation
🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥 |
WalkthroughThe pull request introduces several modifications to the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command 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
|
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: 3
🧹 Outside diff range and nitpick comments (6)
rocketmq-broker/src/offset/manager/consumer_order_info_manager.rs (2)
Line range hint
212-220
: Implement or remove theupdate_lock_free_timestamp
methodThe method
update_lock_free_timestamp
is currently unimplemented. If it's required for the functionality, please provide an appropriate implementation. If not, consider removing it to avoid confusion.Would you like assistance in implementing this method or creating a GitHub issue to track it?
277-295
: Ensure consistency in theDisplay
implementation forOrderInfo
The
Display
implementation forOrderInfo
uses both field names and values. To enhance readability and maintain consistency, consider formatting the struct output more succinctly or using debug formatting if detailed output is required.Optionally, you can simplify the implementation:
- write!( - f, - "OrderInfo {{ popTime: {}, invisibleTime: {:?}, offsetList: {:?}, \ - offsetNextVisibleTime: {:?}, offsetConsumedCount: {:?}, lastConsumeTimestamp: {}, \ - commitOffsetBit: {}, attemptId: {} }}", - self.pop_time, - self.invisible_time, - self.offset_list, - self.offset_next_visible_time, - self.offset_consumed_count, - self.last_consume_timestamp, - self.commit_offset_bit, - self.attempt_id - ) + write!(f, "{:?}", self)This leverages the
Debug
implementation for a concise representation.rocketmq-broker/src/subscription/manager/subscription_group_manager.rs (2)
41-41
: Re-evaluate the visibility change ofsubscription_group_wrapper
The field
subscription_group_wrapper
has been made public (pub(crate)
). Exposing internal mutex-protected data can lead to unintended side effects or race conditions if not managed carefully. Consider providing controlled access through methods instead of making the field public.If external access is necessary, ensure that appropriate getter methods are used to maintain encapsulation.
59-61
: Redundant method due to field visibilityThe method
subscription_group_wrapper()
returns a reference to the now-publicsubscription_group_wrapper
field. Since the field is already public, this method may be redundant.Consider removing the method or keeping the field private to enforce controlled access.
- pub(crate) subscription_group_wrapper: Arc<parking_lot::Mutex<SubscriptionGroupWrapper>>, + subscription_group_wrapper: Arc<parking_lot::Mutex<SubscriptionGroupWrapper>>, ... - pub fn subscription_group_wrapper(&self) -> &Arc<parking_lot::Mutex<SubscriptionGroupWrapper>> { - &self.subscription_group_wrapper - }rocketmq-common/src/common/config.rs (1)
43-59
: Enhance theDisplay
implementation forTopicConfig
The current
Display
implementation manually formats each field, which can be error-prone and hard to maintain. Consider using the{:#?}
formatter for a cleaner and more maintainable output or derivingDisplay
using procedural macros if available.Alternatively, if detailed custom formatting is necessary, ensure all fields are correctly formatted.
- impl Display for TopicConfig { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "TopicConfig {{ topic_name: {:?}, read_queue_nums: {}, write_queue_nums: {}, perm: \ - {}, topic_filter_type: {}, topic_sys_flag: {}, order: {}, attributes: {:?} }}", - self.topic_name, - self.read_queue_nums, - self.write_queue_nums, - self.perm, - self.topic_filter_type, - self.topic_sys_flag, - self.order, - self.attributes - ) - } - } + impl std::fmt::Display for TopicConfig { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } + }This simplifies maintenance and ensures consistency.
rocketmq-broker/src/broker_runtime.rs (1)
244-250
: Consider adding error handling for initialization failures.While the initialization provides all required dependencies, it might be good to add error handling for potential initialization failures. Consider using
Result
to handle cases where the initialization might fail.Example approach:
-let subscription_group_manager = - Arc::new(SubscriptionGroupManager::new(broker_config.clone(), None)); -let consumer_order_info_manager = Arc::new(ConsumerOrderInfoManager::new( - broker_config.clone(), - Arc::new(topic_config_manager.clone()), - subscription_group_manager.clone(), -)); +let subscription_group_manager = SubscriptionGroupManager::new(broker_config.clone(), None) + .map(Arc::new) + .map_err(|e| format!("Failed to initialize SubscriptionGroupManager: {}", e))?; +let consumer_order_info_manager = ConsumerOrderInfoManager::new( + broker_config.clone(), + Arc::new(topic_config_manager.clone()), + subscription_group_manager.clone(), +) + .map(Arc::new) + .map_err(|e| format!("Failed to initialize ConsumerOrderInfoManager: {}", e))?;
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
rocketmq-broker/src/broker_runtime.rs
(3 hunks)rocketmq-broker/src/offset/manager/consumer_order_info_manager.rs
(4 hunks)rocketmq-broker/src/processor/change_invisible_time_processor.rs
(2 hunks)rocketmq-broker/src/subscription/manager/subscription_group_manager.rs
(3 hunks)rocketmq-common/src/common/config.rs
(2 hunks)
🔇 Additional comments (4)
rocketmq-broker/src/subscription/manager/subscription_group_manager.rs (1)
206-206
: Verify the necessity of making SubscriptionGroupWrapper
public
The struct SubscriptionGroupWrapper
is now public (pub(crate)
). Assess if this exposure is required for functionality. If not, keeping it private helps maintain encapsulation and reduces potential misuse.
Please confirm if external modules need direct access to SubscriptionGroupWrapper
.
rocketmq-broker/src/broker_runtime.rs (3)
106-106
: LGTM: Type parameterization improves type safety.
The change to use Arc<ConsumerOrderInfoManager<DefaultMessageStore>>
makes the relationship between the manager and store type explicit, preventing potential type mismatches at compile time.
157-157
: LGTM: Clone implementation correctly handles the parameterized type.
The Clone trait implementation properly maintains the Arc wrapper while handling the parameterized ConsumerOrderInfoManager type.
258-258
: LGTM: Field assignments maintain proper dependency order.
The field assignments are correctly ordered to ensure all dependencies are available, and the types are consistent with the struct definition.
Also applies to: 260-260
for (queue_id, order_info) in qs.iter_mut() { | ||
if *queue_id == topic_config.read_queue_nums as i32 { | ||
queues_to_remove.push(*queue_id); |
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.
Correct the queue ID validation condition
The condition if *queue_id == topic_config.read_queue_nums as i32
may not correctly identify non-existent queues. Since queue IDs range from 0
to read_queue_nums - 1
, the condition should check for queue IDs greater than or equal to read_queue_nums
.
Apply this diff to fix the off-by-one error:
- if *queue_id == topic_config.read_queue_nums as i32 {
+ if *queue_id >= topic_config.read_queue_nums as i32 {
📝 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.
for (queue_id, order_info) in qs.iter_mut() { | |
if *queue_id == topic_config.read_queue_nums as i32 { | |
queues_to_remove.push(*queue_id); | |
for (queue_id, order_info) in qs.iter_mut() { | |
if *queue_id >= topic_config.read_queue_nums as i32 { | |
queues_to_remove.push(*queue_id); |
@@ -59,7 +59,7 @@ pub struct ChangeInvisibleTimeProcessor<MS> { | |||
topic_config_manager: TopicConfigManager, | |||
message_store: ArcMut<MS>, | |||
consumer_offset_manager: Arc<ConsumerOffsetManager>, | |||
consumer_order_info_manager: Arc<ConsumerOrderInfoManager>, | |||
consumer_order_info_manager: Arc<ConsumerOrderInfoManager<MS>>, |
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
Type parameter MS
missing trait bounds
The generic type MS
is used in ChangeInvisibleTimeProcessor<MS>
but lacks trait bounds. This may lead to compilation issues if MS
needs to implement certain traits.
Ensure that MS
has the necessary trait bounds, such as MessageStore
, where required in the implementation.
- pub struct ChangeInvisibleTimeProcessor<MS> {
+ pub struct ChangeInvisibleTimeProcessor<MS: MessageStore> {
Committable suggestion skipped: line range outside the PR's diff.
@@ -74,7 +74,7 @@ | |||
topic_config_manager: TopicConfigManager, | |||
message_store: ArcMut<MS>, | |||
consumer_offset_manager: Arc<ConsumerOffsetManager>, | |||
consumer_order_info_manager: Arc<ConsumerOrderInfoManager>, | |||
consumer_order_info_manager: Arc<ConsumerOrderInfoManager<MS>>, |
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
Update the constructor to reflect trait bounds on MS
Similarly, ensure that the new
method reflects the trait bounds of MS
if it's required for the functionality.
Adjust the implementation to include the trait bounds.
- impl<MS> ChangeInvisibleTimeProcessor<MS> {
+ impl<MS: MessageStore> ChangeInvisibleTimeProcessor<MS> {
Committable suggestion skipped: line range outside the PR's diff.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1765 +/- ##
==========================================
- Coverage 28.23% 28.18% -0.06%
==========================================
Files 467 467
Lines 64684 64800 +116
==========================================
Hits 18265 18265
- Misses 46419 46535 +116 ☔ View full report in Codecov by Sentry. |
Which Issue(s) This PR Fixes(Closes)
Fixes #1763
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
TopicConfig
.Bug Fixes
BrokerRuntime
.Documentation
subscription_group_wrapper
andSubscriptionGroupWrapper
to enhance accessibility.Refactor