From dafb31d208fd107c759e92282fbb2af77e0fc8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Thu, 26 Feb 2026 19:37:16 +0800 Subject: [PATCH] refactor(rpc): use node name accessor in health handlers (#1972) --- crates/common/src/globals.rs | 8 ++++++++ rustfs/src/storage/rpc/health.rs | 12 ++++++------ rustfs/src/storage/rpc/node_service.rs | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/common/src/globals.rs b/crates/common/src/globals.rs index ce708cc53..e561ed2c1 100644 --- a/crates/common/src/globals.rs +++ b/crates/common/src/globals.rs @@ -38,6 +38,14 @@ pub async fn set_global_local_node_name(name: &str) { *GLOBAL_LOCAL_NODE_NAME.write().await = name.to_string(); } +/// Get the global local node name. +/// +/// # Returns +/// * `String` - The local node name. +pub async fn get_global_local_node_name() -> String { + GLOBAL_LOCAL_NODE_NAME.read().await.clone() +} + /// Set the global RustFS initialization time to the current UTC time. pub async fn set_global_init_time_now() { let now = Utc::now(); diff --git a/rustfs/src/storage/rpc/health.rs b/rustfs/src/storage/rpc/health.rs index 5e29a34ed..1f7e6eb98 100644 --- a/rustfs/src/storage/rpc/health.rs +++ b/rustfs/src/storage/rpc/health.rs @@ -19,7 +19,7 @@ impl NodeService { &self, _request: Request, ) -> Result, Status> { - let addr = GLOBAL_LOCAL_NODE_NAME.read().await.clone(); + let addr = get_global_local_node_name().await; let info = get_proc_info(&addr); let mut buf = Vec::new(); if let Err(err) = info.serialize(&mut Serializer::new(&mut buf)) { @@ -40,7 +40,7 @@ impl NodeService { &self, _request: Request, ) -> Result, Status> { - let addr = GLOBAL_LOCAL_NODE_NAME.read().await.clone(); + let addr = get_global_local_node_name().await; let info = get_mem_info(&addr); let mut buf = Vec::new(); if let Err(err) = info.serialize(&mut Serializer::new(&mut buf)) { @@ -61,7 +61,7 @@ impl NodeService { &self, _request: Request, ) -> Result, Status> { - let addr = GLOBAL_LOCAL_NODE_NAME.read().await.clone(); + let addr = get_global_local_node_name().await; let info = get_sys_errors(&addr); let mut buf = Vec::new(); if let Err(err) = info.serialize(&mut Serializer::new(&mut buf)) { @@ -82,7 +82,7 @@ impl NodeService { &self, _request: Request, ) -> Result, Status> { - let addr = GLOBAL_LOCAL_NODE_NAME.read().await.clone(); + let addr = get_global_local_node_name().await; let info = get_sys_config(&addr); let mut buf = Vec::new(); if let Err(err) = info.serialize(&mut Serializer::new(&mut buf)) { @@ -103,7 +103,7 @@ impl NodeService { &self, _request: Request, ) -> Result, Status> { - let addr = GLOBAL_LOCAL_NODE_NAME.read().await.clone(); + let addr = get_global_local_node_name().await; let info = get_sys_services(&addr); let mut buf = Vec::new(); if let Err(err) = info.serialize(&mut Serializer::new(&mut buf)) { @@ -164,7 +164,7 @@ impl NodeService { &self, _request: Request, ) -> Result, Status> { - let addr = GLOBAL_LOCAL_NODE_NAME.read().await.clone(); + let addr = get_global_local_node_name().await; let info = get_net_info(&addr, ""); let mut buf = Vec::new(); if let Err(err) = info.serialize(&mut Serializer::new(&mut buf)) { diff --git a/rustfs/src/storage/rpc/node_service.rs b/rustfs/src/storage/rpc/node_service.rs index 912221ba2..eb12cb9bb 100644 --- a/rustfs/src/storage/rpc/node_service.rs +++ b/rustfs/src/storage/rpc/node_service.rs @@ -16,7 +16,7 @@ use bytes::Bytes; use futures::Stream; use futures_util::future::join_all; use rmp_serde::{Deserializer, Serializer}; -use rustfs_common::{GLOBAL_LOCAL_NODE_NAME, heal_channel::HealOpts}; +use rustfs_common::{get_global_local_node_name, heal_channel::HealOpts}; use rustfs_ecstore::{ admin_server_info::get_local_server_property, bucket::{metadata::load_bucket_metadata, metadata_sys},