Skip to content

Conversation

@mxsm
Copy link
Owner

@mxsm mxsm commented Oct 25, 2025

Which Issue(s) This PR Fixes(Closes)

Fixes #4187

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Refactor
    • Updated internal topic configuration storage from mutex-protected HashMap to concurrent DashMap for improved concurrency handling.
    • Refactored topic configuration ownership model with ArcMut wrapper for shared mutable references.
    • Updated public API signatures for topic configuration methods, including select_topic_config, register_single_topic_all, and related handlers to use new ownership patterns.
    • Removed explicit lock acquisition in iterative operations over topic configurations.
    • Added serialization support for ArcMut-wrapped configurations.

Copilot AI review requested due to automatic review settings October 25, 2025 15:03
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 25, 2025

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between f45dac6 and be21b96.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (24)
  • rocketmq-broker/src/broker_runtime.rs (5 hunks)
  • rocketmq-broker/src/hook/batch_check_before_put_message.rs (1 hunks)
  • rocketmq-broker/src/offset/manager/consumer_order_info_manager.rs (1 hunks)
  • rocketmq-broker/src/out_api/broker_outer_api.rs (2 hunks)
  • rocketmq-broker/src/processor/admin_broker_processor/topic_request_handler.rs (8 hunks)
  • rocketmq-broker/src/processor/notification_processor.rs (1 hunks)
  • rocketmq-broker/src/processor/pop_message_processor.rs (1 hunks)
  • rocketmq-broker/src/processor/processor_service/pop_revive_service.rs (1 hunks)
  • rocketmq-broker/src/processor/send_message_processor.rs (2 hunks)
  • rocketmq-broker/src/slave/slave_synchronize.rs (2 hunks)
  • rocketmq-broker/src/topic/manager/topic_config_manager.rs (28 hunks)
  • rocketmq-broker/src/transaction/queue/transactional_message_bridge.rs (1 hunks)
  • rocketmq-broker/src/util/hook_utils.rs (4 hunks)
  • rocketmq-common/src/utils/cleanup_policy_utils.rs (2 hunks)
  • rocketmq-common/src/utils/queue_type_utils.rs (2 hunks)
  • rocketmq-remoting/src/protocol/body/create_topic_list_request_body.rs (1 hunks)
  • rocketmq-remoting/src/protocol/body/topic_info_wrapper.rs (1 hunks)
  • rocketmq-store/Cargo.toml (1 hunks)
  • rocketmq-store/src/base/append_message_callback.rs (3 hunks)
  • rocketmq-store/src/log_file/commit_log.rs (4 hunks)
  • rocketmq-store/src/message_store/local_file_message_store.rs (7 hunks)
  • rocketmq-store/src/queue/local_file_consume_queue_store.rs (2 hunks)
  • rocketmq/Cargo.toml (1 hunks)
  • rocketmq/src/arc_mut.rs (2 hunks)
 ________________________________
< NVIDIA inside, Rabbit outside. >
 --------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

Tip

You can disable poems in the walkthrough.

Disable the reviews.poem setting in your project's settings in CodeRabbit to disable the poems in the walkthrough.

Note

Other AI code review bot(s) detected

CodeRabbit 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 docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-4187

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rocketmq-rust-bot
Copy link
Collaborator

🔊@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💥.

@rocketmq-rust-robot rocketmq-rust-robot added the refactor♻️ refactor code label Oct 25, 2025
Copy link
Contributor

Copilot AI left a 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>>> with Arc<DashMap<CheetahString, ArcMut<TopicConfig>>> throughout the codebase
  • Added Serialize/Deserialize implementations for ArcMut<T> to support the new configuration structure
  • Created helper functions get_cq_type_arc_mut, is_batch_cq_arc_mut, and get_delete_policy_arc_mut to handle ArcMut<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 inner try_unwrap().unwrap() will panic if there are other references to the ArcMut, but provides no context about which topic config failed or why. Consider using expect() 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() };
Copy link

Copilot AI Oct 25, 2025

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.

Copilot uses AI. Check for mistakes.
config.order = is_order;

self.put_topic_config(config.clone());
let current_ref = self.put_topic_config(config);
Copy link

Copilot AI Oct 25, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +464 to +465
//can optimize todo
self.update_topic_config(topic_config.clone());
Copy link

Copilot AI Oct 25, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +157 to +158
.get_topic_config(topic.as_str())
.clone();
Copy link

Copilot AI Oct 25, 2025

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.

Suggested change
.get_topic_config(topic.as_str())
.clone();
.get_topic_config(topic.as_str());

Copilot uses AI. Check for mistakes.
@rocketmq-rust-bot
Copy link
Collaborator

🔊@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
Copy link

codecov bot commented Oct 26, 2025

Codecov Report

❌ Patch coverage is 10.30928% with 174 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.71%. Comparing base (f45dac6) to head (be21b96).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...q-broker/src/topic/manager/topic_config_manager.rs 0.00% 90 Missing ⚠️
rocketmq-common/src/utils/cleanup_policy_utils.rs 0.00% 12 Missing ⚠️
rocketmq/src/arc_mut.rs 0.00% 12 Missing ⚠️
...or/admin_broker_processor/topic_request_handler.rs 0.00% 10 Missing ⚠️
rocketmq-common/src/utils/queue_type_utils.rs 61.11% 7 Missing ⚠️
rocketmq-broker/src/broker_runtime.rs 0.00% 6 Missing ⚠️
rocketmq-broker/src/slave/slave_synchronize.rs 0.00% 6 Missing ⚠️
...tore/src/message_store/local_file_message_store.rs 0.00% 6 Missing ⚠️
rocketmq-broker/src/out_api/broker_outer_api.rs 0.00% 5 Missing ⚠️
rocketmq-store/src/log_file/commit_log.rs 0.00% 5 Missing ⚠️
... and 10 more
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@rocketmq-rust-bot rocketmq-rust-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rocketmq-rust-bot rocketmq-rust-bot merged commit 9274a64 into main Oct 26, 2025
15 of 18 checks passed
@mxsm mxsm deleted the refactor-4187 branch October 26, 2025 00:57
@rocketmq-rust-bot rocketmq-rust-bot added approved PR has approved and removed ready to review waiting-review waiting review this PR labels Oct 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI review first Ai review pr first approved PR has approved auto merge refactor♻️ refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor♻️]Refactor topic configuration handling to use DashMap for improved concurrency

4 participants