-
Notifications
You must be signed in to change notification settings - Fork 113
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 #2172]🤡Implement name server graceful shutdown⚡️ #2173
Conversation
WalkthroughThe pull request introduces a graceful shutdown mechanism for the RocketMQ Name Server runtime. By adding a 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💥. |
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: 2
🧹 Nitpick comments (2)
rocketmq-namesrv/src/bootstrap.rs (2)
70-74
: Simplifytokio::select!
with a Single BranchIn
wait_for_signal_inner
, thetokio::select!
macro is used with only one future. Since there's only one asynchronous operation to await, you can simplify the code by directly awaitingwait_for_signal()
.Apply this diff to simplify the code:
async fn wait_for_signal_inner(shutdown_tx: broadcast::Sender<()>) { - tokio::select! { - _ = wait_for_signal() => { - info!("Received signal, initiating shutdown..."); - } - } + wait_for_signal().await; + info!("Received signal, initiating shutdown..."); // Send shutdown signal to all tasks let _ = shutdown_tx.send(()); }
101-106
: Simplifytokio::select!
with a Single Branch instart
MethodIn the
start
method, thetokio::select!
macro is used with only one future. You can simplify the code by directly awaiting therecv()
method onshutdown_rx
.Apply this diff to simplify the code:
tokio::select! { - _ = self.shutdown_rx.as_mut().unwrap().recv() => { - info!("Shutdown received, initiating graceful shutdown..."); - self.shutdown().await; - } + _ = self.shutdown_rx.recv() => { + info!("Shutdown received, initiating graceful shutdown..."); + self.shutdown().await; + } }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
rocketmq-namesrv/src/bootstrap.rs
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
- GitHub Check: build (windows-latest, nightly)
- GitHub Check: build (windows-latest, stable)
- GitHub Check: build (macos-latest, nightly)
- GitHub Check: build (macos-latest, stable)
- GitHub Check: build (ubuntu-latest, nightly)
- GitHub Check: test
- GitHub Check: build (ubuntu-latest, stable)
- GitHub Check: build
- GitHub Check: auto-approve
// receiver for shutdown signal | ||
shutdown_rx: Option<tokio::sync::broadcast::Receiver<()>>, |
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.
Potential Panic Due to Unwrapping shutdown_rx
The shutdown_rx
field is an Option
, but in the start
method, it is unwrapped using unwrap()
without checking if it is Some
. This could lead to a panic if shutdown_rx
is None
.
To prevent potential runtime panics, consider making shutdown_rx
a required field by removing the Option
, ensuring it is always initialized before start
is called.
Apply this diff to remove the Option
and enforce initialization:
struct NameServerRuntime {
name_server_runtime: Option<RocketMQRuntime>,
inner: ArcMut<NameServerRuntimeInner>,
- shutdown_rx: Option<tokio::sync::broadcast::Receiver<()>>,
+ shutdown_rx: tokio::sync::broadcast::Receiver<()>,
}
impl NameServerBootstrap {
pub async fn boot(mut self) {
let (shutdown_tx, shutdown_rx) = broadcast::channel(1);
- self.name_server_runtime.shutdown_rx = Some(shutdown_rx);
+ self.name_server_runtime.shutdown_rx = shutdown_rx;
tokio::join!(
self.name_server_runtime.start(),
wait_for_signal_inner(shutdown_tx)
);
}
}
impl NameServerRuntime {
pub async fn start(&mut self) {
// ...
tokio::select! {
- _ = self.shutdown_rx.as_mut().unwrap().recv() => {
+ _ = self.shutdown_rx.recv() => {
info!("Shutdown received, initiating graceful shutdown...");
self.shutdown().await;
}
}
}
// ...
async fn shutdown(&mut self) {
// Shutdown logic
}
}
Committable suggestion skipped: line range outside the PR's diff.
fn shutdown(&mut self) { | ||
info!("Rocketmq NameServer(Rust) gracefully shutdown completed"); | ||
} |
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
Implement Graceful Shutdown Logic in shutdown()
The shutdown()
method currently only logs a message without performing any actual shutdown operations. To achieve a graceful shutdown, you should:
- Stop the
RocketMQServer
instance to close the server gracefully. - Shutdown the
remoting_client
to close any client connections. - Cancel any running tasks or spawned threads.
- Release any held resources.
Consider updating the shutdown()
method as follows:
impl NameServerRuntime {
- fn shutdown(&mut self) {
+ async fn shutdown(&mut self) {
+ // Stop the remoting client
+ self.inner.remoting_client.shutdown().await;
+
+ // Signal the server to stop (assuming you have a mechanism to do so)
+ // e.g., self.server.shutdown().await;
+
+ // Additional cleanup if necessary
+
info!("Rocketmq NameServer(Rust) gracefully shutdown completed");
}
}
Ensure that the components you are attempting to shut down have appropriate shutdown
methods and that you await their completion if they are async operations.
Committable suggestion skipped: line range outside the PR's diff.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2173 +/- ##
==========================================
- Coverage 28.76% 28.75% -0.01%
==========================================
Files 498 498
Lines 71038 71054 +16
==========================================
Hits 20435 20435
- Misses 50603 50619 +16 ☔ 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.
LGTM
Which Issue(s) This PR Fixes(Closes)
Fixes #2172
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
Refactor