-
Couldn't load subscription status.
- Fork 176
[ISSUE #4187]♻️Refactor topic configuration handling to use DashMap for improved concurrency #4206
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
…or improved concurrency
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (24)
Tip You can disable poems in the walkthrough.Disable the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🔊@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💥. |
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.
Pull Request Overview
This PR refactors topic configuration handling by replacing parking_lot::Mutex<HashMap> with DashMap for improved concurrency. The change eliminates the need for explicit locking when accessing topic configurations, as DashMap provides concurrent access through internal lock striping.
Key changes:
- Replaced
Arc<parking_lot::Mutex<HashMap<CheetahString, TopicConfig>>>withArc<DashMap<CheetahString, ArcMut<TopicConfig>>>throughout the codebase - Added
Serialize/Deserializeimplementations forArcMut<T>to support the new configuration structure - Created helper functions
get_cq_type_arc_mut,is_batch_cq_arc_mut, andget_delete_policy_arc_mutto handleArcMut<TopicConfig>references
Reviewed Changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| rocketmq/src/arc_mut.rs | Added serde serialization support for ArcMut |
| rocketmq/Cargo.toml | Added serde dependency |
| rocketmq-store/src/queue/local_file_consume_queue_store.rs | Updated to use new arc_mut helper functions |
| rocketmq-store/src/message_store/local_file_message_store.rs | Migrated from Mutex-wrapped HashMap to DashMap |
| rocketmq-store/src/log_file/commit_log.rs | Updated function signatures for DashMap |
| rocketmq-store/src/base/append_message_callback.rs | Updated topic_config_table type |
| rocketmq-store/Cargo.toml | Added dashmap dependency |
| rocketmq-remoting/src/protocol/body/topic_info_wrapper.rs | Added helper method for taking ownership |
| rocketmq-remoting/src/protocol/body/create_topic_list_request_body.rs | Changed to use ArcMut |
| rocketmq-common/src/utils/queue_type_utils.rs | Added arc_mut helper functions |
| rocketmq-common/src/utils/cleanup_policy_utils.rs | Added arc_mut helper function |
| rocketmq-broker/src/util/hook_utils.rs | Migrated to DashMap usage |
| rocketmq-broker/src/transaction/queue/transactional_message_bridge.rs | Updated return type |
| rocketmq-broker/src/topic/manager/topic_config_manager.rs | Major refactoring to use DashMap instead of Mutex |
| rocketmq-broker/src/slave/slave_synchronize.rs | Updated synchronization logic |
| rocketmq-broker/src/processor/* | Multiple processors updated for new types |
| rocketmq-broker/src/out_api/broker_outer_api.rs | Updated function signatures |
| rocketmq-broker/src/offset/manager/consumer_order_info_manager.rs | Fixed format specifier |
| rocketmq-broker/src/hook/batch_check_before_put_message.rs | Migrated to DashMap |
| rocketmq-broker/src/broker_runtime.rs | Updated for DashMap access patterns |
Comments suppressed due to low confidence (1)
rocketmq-broker/src/topic/manager/topic_config_manager.rs:1
- Double
unwrap()calls can panic without helpful context. The innertry_unwrap().unwrap()will panic if there are other references to theArcMut, but provides no context about which topic config failed or why. Consider usingexpect()with descriptive messages or proper error handling.
/*
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| where | ||
| S: Serializer, | ||
| { | ||
| let inner_ref = unsafe { &*self.inner.get() }; |
Copilot
AI
Oct 25, 2025
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.
The serialize implementation uses unsafe code to access the inner value without synchronization. If serialization occurs while another thread is mutating the value through ArcMut, this could lead to undefined behavior. Consider using interior mutability with proper synchronization (e.g., RwLock) or document that serialization must only occur when no concurrent mutations are possible.
| config.order = is_order; | ||
|
|
||
| self.put_topic_config(config.clone()); | ||
| let current_ref = self.put_topic_config(config); |
Copilot
AI
Oct 25, 2025
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.
The variable current_ref is assigned but the original config variable is shadowed. The function put_topic_config consumes config and returns the previous value (or None), not the newly inserted value. This means current_ref contains the old value that was replaced, not the newly inserted config. The return statement at line 430 should likely return the newly created config instead.
| //can optimize todo | ||
| self.update_topic_config(topic_config.clone()); |
Copilot
AI
Oct 25, 2025
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.
Each iteration clones the ArcMut<TopicConfig>, which increments the reference count. Since update_topic_config doesn't require ownership of the clone, consider refactoring to avoid unnecessary clones in a loop, or document why the clone is necessary here.
| .get_topic_config(topic.as_str()) | ||
| .clone(); |
Copilot
AI
Oct 25, 2025
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.
The call chain .get_topic_config(topic.as_str()).clone() is redundant. The get_topic_config method already returns Option<ArcMut<TopicConfig>> which clones the ArcMut internally via as_deref().cloned(). The additional .clone() here creates an unnecessary extra reference count increment.
| .get_topic_config(topic.as_str()) | |
| .clone(); | |
| .get_topic_config(topic.as_str()); |
|
🔊@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 Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4206 +/- ##
==========================================
- Coverage 26.72% 26.71% -0.01%
==========================================
Files 578 578
Lines 82009 82071 +62
==========================================
+ Hits 21914 21927 +13
- Misses 60095 60144 +49 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
LGTM
Which Issue(s) This PR Fixes(Closes)
Fixes #4187
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
select_topic_config,register_single_topic_all, and related handlers to use new ownership patterns.