Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[ISSUE #2177]⚡️Optimize name server graceful shutdown #2178

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions rocketmq-namesrv/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ impl NameServerRuntime {
}

fn shutdown(&mut self) {
if let Some(runtime) = self.name_server_runtime.take() {
runtime.shutdown();
}
self.inner
.route_info_manager_mut()
.un_register_service
.shutdown();
info!("Rocketmq NameServer(Rust) gracefully shutdown completed");
}

Expand Down Expand Up @@ -144,9 +151,9 @@ impl NameServerRuntime {

impl Drop for NameServerRuntime {
fn drop(&mut self) {
if let Some(runtime) = self.name_server_runtime.take() {
runtime.shutdown();
}
// if let Some(runtime) = self.name_server_runtime.take() {
// runtime.shutdown();
// }
}
}

Expand Down
13 changes: 13 additions & 0 deletions rocketmq-namesrv/src/route/batch_unregistration_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use std::sync::Arc;

use rocketmq_remoting::protocol::header::namesrv::broker_request::UnRegisterBrokerRequestHeader;
use rocketmq_rust::ArcMut;
use tokio::sync::Notify;
use tracing::info;
use tracing::warn;

Expand All @@ -25,6 +28,7 @@ pub(crate) struct BatchUnregistrationService {
name_server_runtime_inner: ArcMut<NameServerRuntimeInner>,
tx: tokio::sync::mpsc::Sender<UnRegisterBrokerRequestHeader>,
rx: Option<tokio::sync::mpsc::Receiver<UnRegisterBrokerRequestHeader>>,
shutdown_notify: Arc<Notify>,
}

impl BatchUnregistrationService {
Expand All @@ -38,6 +42,7 @@ impl BatchUnregistrationService {
name_server_runtime_inner,
tx,
rx: Some(rx),
shutdown_notify: Default::default(),
}
}

Expand All @@ -52,6 +57,7 @@ impl BatchUnregistrationService {
pub fn start(&mut self) {
let mut name_server_runtime_inner = self.name_server_runtime_inner.clone();
let mut rx = self.rx.take().expect("rx is None");
let shutdown_notify = self.shutdown_notify.clone();
let limit = 10;
tokio::spawn(async move {
info!(">>>>>>>>BatchUnregistrationService started<<<<<<<<<<<<<<<<<<<");
Expand All @@ -61,8 +67,15 @@ impl BatchUnregistrationService {
_ = rx.recv_many(&mut unregistration_requests,limit) => {
name_server_runtime_inner.route_info_manager_mut().un_register_broker(unregistration_requests);
}
_ = shutdown_notify.notified() => {
break;
}
}
}
});
}

pub fn shutdown(&self) {
self.shutdown_notify.notify_one();
}
}
4 changes: 4 additions & 0 deletions rocketmq-namesrv/src/route/route_info_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,4 +1217,8 @@ impl RouteInfoManager {
}
});
}

pub fn shutdown(&self) {
self.un_register_service.shutdown();
}
}
Loading