Skip to content
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 #1021]🚀Support mq client instance clean offline broker🎉 #1024

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Sep 30, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #1021

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features

    • Introduced a new constant for lock timeout to enhance concurrency control.
    • Added a method to check if broker addresses exist in the topic route table.
  • Improvements

    • Updated locking mechanisms for better broker management and heartbeat handling.

Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Walkthrough

The changes in this pull request focus on improving the locking mechanisms and broker management within the MQClientInstance class in the RocketMQ client. A new constant for lock timeout is introduced, and several methods are updated to enhance concurrency control. The modifications aim to streamline the handling of broker connections and heartbeats, ensuring more robust management of offline brokers.

Changes

File Path Change Summary
rocketmq-client/src/factory/mq_client_instance.rs - Added constant LOCK_TIMEOUT_MILLIS with a value of 3000 milliseconds.
- Changed lock_namesrv type from Arc<Mutex<()>> to Arc<RocketMQTokioMutex<()>>.
- Updated clean_offline_broker to utilize the new lock timeout.
- Modified send_heartbeat_to_all_broker_with_lock and send_heartbeat_to_all_broker_with_lock_v2 for streamlined locking.
- Introduced is_broker_addr_exist_in_topic_route_table method.

Sequence Diagram(s)

sequenceDiagram
    participant Client as MQClientInstance
    participant Broker as Broker Management
    participant RouteTable as Topic Route Table

    Client->>Broker: Request to clean offline brokers
    Broker->>RouteTable: Check for offline brokers
    RouteTable-->>Broker: Return list of offline brokers
    Broker->>Client: Remove offline brokers from management
Loading

Assessment against linked issues

Objective Addressed Explanation
Support mq client instance clean offline broker (#1021)

Possibly related PRs

Suggested reviewers

  • SpaceXCN

Poem

🐰 In the meadow, where the bunnies play,
New locks and brokers brighten the day.
With a hop and a skip, we manage with glee,
Offline brokers, now set free!
Hooray for the changes, let’s dance and cheer,
For a robust client, we hold dear! 🌼


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mxsm
Copy link
Owner Author

mxsm commented Sep 30, 2024

🚀Thanks for your contribution🎉. CodeRabbit(AI) will review your code first🔥

@TeslaRustor TeslaRustor added approved PR has approved and removed ready to review labels Sep 30, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3dfebe6 and 9e46d6d.

📒 Files selected for processing (1)
  • rocketmq-client/src/factory/mq_client_instance.rs (9 hunks)

@@ -64,6 +63,8 @@ use crate::producer::producer_impl::mq_producer_inner::MQProducerInner;
use crate::producer::producer_impl::topic_publish_info::TopicPublishInfo;
use crate::Result;

const LOCK_TIMEOUT_MILLIS: u64 = 3000;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Suggestion: Make LOCK_TIMEOUT_MILLIS configurable

Currently, LOCK_TIMEOUT_MILLIS is hardcoded to 3000 milliseconds. Consider making this value configurable through client settings to provide flexibility for different environments or use cases.

Comment on lines +636 to +667
let lock = self
.lock_namesrv
.try_lock_timeout(Duration::from_millis(LOCK_TIMEOUT_MILLIS))
.await;
if let Some(lock) = lock {
let mut broker_addr_table = self.broker_addr_table.write().await;
let mut updated_table = HashMap::with_capacity(broker_addr_table.len());
let mut broker_name_set = HashSet::new();
for (broker_name, one_table) in broker_addr_table.iter() {
let mut clone_addr_table = one_table.clone();
let mut remove_id_set = HashSet::new();
for (id, addr) in one_table.iter() {
if !self.is_broker_addr_exist_in_topic_route_table(addr).await {
remove_id_set.insert(*id);
}
}
clone_addr_table.retain(|k, _| !remove_id_set.contains(k));
if clone_addr_table.is_empty() {
info!(
"the broker[{}] name's host is offline, remove it",
broker_name
);
broker_name_set.insert(broker_name.clone());
} else {
updated_table.insert(broker_name.clone(), clone_addr_table);
}
}
broker_addr_table.retain(|k, _| !broker_name_set.contains(k));
if !updated_table.is_empty() {
broker_addr_table.extend(updated_table);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle lock acquisition failure in clean_offline_broker

If try_lock_timeout fails to acquire the lock_namesrv lock, the method exits silently without any logging or error handling. Consider adding an else block to handle the failure case, such as logging a warning or error, to improve observability and debugging.

Comment on lines +776 to +781
if self.client_config.use_heartbeat_v2 {
unimplemented!("sendHeartbeatToBrokerV2")
} else {
self.send_heartbeat_to_broker_inner(id, broker_name, addr, &heartbeat_data)
.await
};
drop(lock);
result
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement sendHeartbeatToBrokerV2 or handle unimplemented case

In send_heartbeat_to_broker, when use_heartbeat_v2 is true, the method calls unimplemented!("sendHeartbeatToBrokerV2"), which will cause a panic at runtime if this path is executed. Please implement the sendHeartbeatToBrokerV2 method or handle this case to prevent potential runtime panics.

@mxsm mxsm merged commit 3ac6cd0 into main Sep 30, 2024
17 checks passed
@mxsm mxsm deleted the feature-1021 branch September 30, 2024 09:39
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 0% with 37 lines in your changes missing coverage. Please review.

Project coverage is 19.85%. Comparing base (3dfebe6) to head (9e46d6d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
rocketmq-client/src/factory/mq_client_instance.rs 0.00% 37 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1024      +/-   ##
==========================================
- Coverage   19.87%   19.85%   -0.03%     
==========================================
  Files         420      420              
  Lines       34594    34624      +30     
==========================================
- Hits         6876     6875       -1     
- Misses      27718    27749      +31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved PR has approved auto merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature🚀] Support mq client instance clean offline broker
2 participants