refactor(runtime): normalize legacy global names (#4095)

This commit is contained in:
Zhengchao An
2026-06-30 05:13:06 +08:00
committed by GitHub
parent 90f9c24503
commit cbd527cd6e
4 changed files with 65 additions and 64 deletions
+25 -24
View File
@@ -42,27 +42,28 @@ pub const DISK_RESERVE_FRACTION: f64 = 0.15;
// These should be migrated to AppContext over time.
// See issue #730 for migration plan.
//
// Tier A (needs migration): GLOBAL_OBJECT_API, GLOBAL_IsErasure*, GLOBAL_LOCAL_DISK_*,
// GLOBAL_RootDiskThreshold, GLOBAL_LifecycleSys, GLOBAL_EventNotifier, etc.
// Tier A (needs migration): GLOBAL_OBJECT_API, GLOBAL_IS_ERASURE*, GLOBAL_LOCAL_DISK_*,
// GLOBAL_ROOT_DISK_THRESHOLD, GLOBAL_LIFECYCLE_SYS, GLOBAL_EVENT_NOTIFIER, etc.
// Tier B (keep as static): GLOBAL_RUSTFS_PORT, GLOBAL_REGION, env var caches, etc.
lazy_static! {
static ref GLOBAL_RUSTFS_PORT: OnceLock<u16> = OnceLock::new();
static ref GLOBAL_DEPLOYMENT_ID: OnceLock<Uuid> = OnceLock::new();
pub static ref GLOBAL_OBJECT_API: OnceLock<Arc<ECStore>> = OnceLock::new();
pub static ref GLOBAL_IsErasure: RwLock<bool> = RwLock::new(false);
pub static ref GLOBAL_IsDistErasure: RwLock<bool> = RwLock::new(false);
pub static ref GLOBAL_IsErasureSD: RwLock<bool> = RwLock::new(false);
pub static ref GLOBAL_IS_ERASURE: RwLock<bool> = RwLock::new(false);
pub static ref GLOBAL_IS_DIST_ERASURE: RwLock<bool> = RwLock::new(false);
pub static ref GLOBAL_IS_ERASURE_SD: RwLock<bool> = RwLock::new(false);
pub static ref GLOBAL_LOCAL_DISK_MAP: Arc<RwLock<HashMap<String, Option<DiskStore>>>> = Arc::new(RwLock::new(HashMap::new()));
pub static ref GLOBAL_LOCAL_DISK_ID_MAP: Arc<RwLock<HashMap<Uuid, String>>> = Arc::new(RwLock::new(HashMap::new()));
pub static ref GLOBAL_LOCAL_DISK_SET_DRIVES: Arc<RwLock<TypeLocalDiskSetDrives>> = Arc::new(RwLock::new(Vec::new()));
pub static ref GLOBAL_Endpoints: OnceLock<EndpointServerPools> = OnceLock::new();
pub static ref GLOBAL_RootDiskThreshold: RwLock<u64> = RwLock::new(0);
pub static ref GLOBAL_TierConfigMgr: Arc<RwLock<TierConfigMgr>> = TierConfigMgr::new();
pub static ref GLOBAL_LifecycleSys: Arc<LifecycleSys> = LifecycleSys::new();
pub static ref GLOBAL_EventNotifier: Arc<RwLock<EventNotifier>> = EventNotifier::new();
pub static ref GLOBAL_ENDPOINTS: OnceLock<EndpointServerPools> = OnceLock::new();
pub static ref GLOBAL_ROOT_DISK_THRESHOLD: RwLock<u64> = RwLock::new(0);
pub static ref GLOBAL_TIER_CONFIG_MGR: Arc<RwLock<TierConfigMgr>> = TierConfigMgr::new();
pub static ref GLOBAL_LIFECYCLE_SYS: Arc<LifecycleSys> = LifecycleSys::new();
pub static ref GLOBAL_EVENT_NOTIFIER: Arc<RwLock<EventNotifier>> = EventNotifier::new();
pub static ref GLOBAL_BOOT_TIME: OnceCell<SystemTime> = OnceCell::new();
pub static ref GLOBAL_LocalNodeName: String = "127.0.0.1:9000".to_string();
pub static ref GLOBAL_LocalNodeNameHex: String = rustfs_utils::crypto::hex(GLOBAL_LocalNodeName.as_bytes());
pub static ref GLOBAL_LOCAL_NODE_NAME_FALLBACK: String = "127.0.0.1:9000".to_string();
pub static ref GLOBAL_LOCAL_NODE_NAME_HEX_FALLBACK: String =
rustfs_utils::crypto::hex(GLOBAL_LOCAL_NODE_NAME_FALLBACK.as_bytes());
pub static ref GLOBAL_REGION: OnceLock<s3s::region::Region> = OnceLock::new();
pub static ref GLOBAL_LOCAL_LOCK_CLIENT: OnceLock<Arc<dyn LockClient>> = OnceLock::new();
pub static ref GLOBAL_LOCK_CLIENTS: OnceLock<HashMap<String, Arc<dyn LockClient>>> = OnceLock::new();
@@ -145,9 +146,9 @@ pub fn get_global_deployment_id() -> Option<String> {
/// * None
///
pub fn set_global_endpoints(eps: Vec<PoolEndpoints>) {
GLOBAL_Endpoints
GLOBAL_ENDPOINTS
.set(EndpointServerPools::from(eps))
.expect("GLOBAL_Endpoints should be initialized once during storage startup")
.expect("GLOBAL_ENDPOINTS should be initialized once during storage startup")
}
/// Get the global endpoints
@@ -156,7 +157,7 @@ pub fn set_global_endpoints(eps: Vec<PoolEndpoints>) {
/// * `EndpointServerPools` - The global endpoints
///
pub fn get_global_endpoints() -> EndpointServerPools {
if let Some(eps) = GLOBAL_Endpoints.get() {
if let Some(eps) = GLOBAL_ENDPOINTS.get() {
eps.clone()
} else {
EndpointServerPools::default()
@@ -164,7 +165,7 @@ pub fn get_global_endpoints() -> EndpointServerPools {
}
pub fn get_global_endpoints_opt() -> Option<EndpointServerPools> {
GLOBAL_Endpoints.get().cloned()
GLOBAL_ENDPOINTS.get().cloned()
}
#[cfg(test)]
@@ -179,7 +180,7 @@ pub async fn is_first_cluster_node_local() -> bool {
}
pub fn get_global_tier_config_mgr() -> Arc<RwLock<TierConfigMgr>> {
GLOBAL_TierConfigMgr.clone()
GLOBAL_TIER_CONFIG_MGR.clone()
}
/// Create a new object layer instance
@@ -225,7 +226,7 @@ pub async fn set_object_layer(o: Arc<ECStore>) {
/// * `bool` - True if the setup type is distributed erasure coding, false otherwise
///
pub async fn is_dist_erasure() -> bool {
let lock = GLOBAL_IsDistErasure.read().await;
let lock = GLOBAL_IS_DIST_ERASURE.read().await;
*lock
}
@@ -235,7 +236,7 @@ pub async fn is_dist_erasure() -> bool {
/// * `bool` - True if the setup type is erasure coding with single data center, false otherwise
///
pub async fn is_erasure_sd() -> bool {
let lock = GLOBAL_IsErasureSD.read().await;
let lock = GLOBAL_IS_ERASURE_SD.read().await;
*lock
}
@@ -245,7 +246,7 @@ pub async fn is_erasure_sd() -> bool {
/// * `bool` - True if the setup type is erasure coding, false otherwise
///
pub async fn is_erasure() -> bool {
let lock = GLOBAL_IsErasure.read().await;
let lock = GLOBAL_IS_ERASURE.read().await;
*lock
}
@@ -257,22 +258,22 @@ pub async fn is_erasure() -> bool {
/// # Returns
/// * None
pub async fn update_erasure_type(setup_type: SetupType) {
let mut is_erasure = GLOBAL_IsErasure.write().await;
let mut is_erasure = GLOBAL_IS_ERASURE.write().await;
*is_erasure = setup_type == SetupType::Erasure;
let mut is_dist_erasure = GLOBAL_IsDistErasure.write().await;
let mut is_dist_erasure = GLOBAL_IS_DIST_ERASURE.write().await;
*is_dist_erasure = setup_type == SetupType::DistErasure;
if *is_dist_erasure {
*is_erasure = true
}
let mut is_erasure_sd = GLOBAL_IsErasureSD.write().await;
let mut is_erasure_sd = GLOBAL_IS_ERASURE_SD.write().await;
*is_erasure_sd = setup_type == SetupType::ErasureSD;
}
// pub fn is_legacy() -> bool {
// if let Some(endpoints) = GLOBAL_Endpoints.get() {
// if let Some(endpoints) = GLOBAL_ENDPOINTS.get() {
// endpoints.as_ref().len() == 1 && endpoints.as_ref()[0].legacy
// } else {
// false
+15 -15
View File
@@ -29,13 +29,13 @@ use crate::{
error::Result,
layout::endpoints::{EndpointServerPools, SetupType},
runtime::global::{
GLOBAL_BOOT_TIME, GLOBAL_EventNotifier, GLOBAL_IsErasureSD, GLOBAL_LOCAL_DISK_ID_MAP, GLOBAL_LOCAL_DISK_MAP,
GLOBAL_LOCAL_DISK_SET_DRIVES, GLOBAL_LifecycleSys, GLOBAL_LocalNodeName, GLOBAL_RootDiskThreshold, GLOBAL_TierConfigMgr,
TypeLocalDiskSetDrives, get_background_services_cancel_token, get_global_bucket_monitor, get_global_deployment_id,
get_global_endpoints, get_global_endpoints_opt, get_global_lock_clients, get_global_region, get_global_tier_config_mgr,
global_rustfs_port, init_global_bucket_monitor, is_dist_erasure, is_erasure, is_first_cluster_node_local,
resolve_object_store_handle, set_global_deployment_id, set_global_lock_client, set_global_lock_clients, set_object_layer,
update_erasure_type,
GLOBAL_BOOT_TIME, GLOBAL_EVENT_NOTIFIER, GLOBAL_IS_ERASURE_SD, GLOBAL_LIFECYCLE_SYS, GLOBAL_LOCAL_DISK_ID_MAP,
GLOBAL_LOCAL_DISK_MAP, GLOBAL_LOCAL_DISK_SET_DRIVES, GLOBAL_LOCAL_NODE_NAME_FALLBACK, GLOBAL_ROOT_DISK_THRESHOLD,
GLOBAL_TIER_CONFIG_MGR, TypeLocalDiskSetDrives, get_background_services_cancel_token, get_global_bucket_monitor,
get_global_deployment_id, get_global_endpoints, get_global_endpoints_opt, get_global_lock_clients, get_global_region,
get_global_tier_config_mgr, global_rustfs_port, init_global_bucket_monitor, is_dist_erasure, is_erasure,
is_first_cluster_node_local, resolve_object_store_handle, set_global_deployment_id, set_global_lock_client,
set_global_lock_clients, set_object_layer, update_erasure_type,
},
services::batch_processor::{GlobalBatchProcessors, get_global_processors},
services::event_notification::EventNotifier,
@@ -145,7 +145,7 @@ pub(crate) async fn setup_is_dist_erasure() -> bool {
}
pub async fn setup_is_erasure_sd() -> bool {
*GLOBAL_IsErasureSD.read().await
*GLOBAL_IS_ERASURE_SD.read().await
}
pub(crate) async fn current_setup_type() -> SetupType {
@@ -173,7 +173,7 @@ pub(crate) async fn set_local_node_name(node_name: String) {
}
pub(crate) fn default_local_node_name() -> String {
GLOBAL_LocalNodeName.to_string()
GLOBAL_LOCAL_NODE_NAME_FALLBACK.to_string()
}
pub(crate) fn rustfs_port() -> u16 {
@@ -212,10 +212,10 @@ pub(crate) async fn scanner_init_time() -> Option<chrono::DateTime<chrono::Utc>>
}
pub(crate) async fn root_disk_threshold_for_erasure_disk() -> Option<u64> {
if *GLOBAL_IsErasureSD.read().await {
if *GLOBAL_IS_ERASURE_SD.read().await {
None
} else {
Some(*GLOBAL_RootDiskThreshold.read().await)
Some(*GLOBAL_ROOT_DISK_THRESHOLD.read().await)
}
}
@@ -349,7 +349,7 @@ pub fn global_tier_config_mgr() -> Arc<RwLock<TierConfigMgr>> {
}
pub(crate) async fn bucket_lifecycle_config(bucket: &str) -> Option<BucketLifecycleConfiguration> {
GLOBAL_LifecycleSys.get(bucket).await
GLOBAL_LIFECYCLE_SYS.get(bucket).await
}
pub(crate) fn delete_bucket_monitor_entry(bucket: &str) {
@@ -384,7 +384,7 @@ pub(crate) fn local_disk_set_drives_handle() -> Arc<RwLock<TypeLocalDiskSetDrive
}
pub(crate) fn tier_config_mgr_handle() -> Arc<RwLock<TierConfigMgr>> {
GLOBAL_TierConfigMgr.clone()
GLOBAL_TIER_CONFIG_MGR.clone()
}
pub fn expiry_state_handle() -> Arc<RwLock<ExpiryState>> {
@@ -396,7 +396,7 @@ pub fn transition_state_handle() -> Arc<TransitionState> {
}
pub(crate) fn event_notifier_handle() -> Arc<RwLock<EventNotifier>> {
GLOBAL_EventNotifier.clone()
GLOBAL_EVENT_NOTIFIER.clone()
}
pub(crate) async fn local_disk_by_path(path: &str) -> Option<DiskStore> {
@@ -518,7 +518,7 @@ pub(crate) async fn initialize_local_disk_maps(endpoint_pools: EndpointServerPoo
}
pub(crate) async fn init_tier_config_mgr(store: Arc<ECStore>) -> Result<()> {
GLOBAL_TierConfigMgr.write().await.init(store).await
GLOBAL_TIER_CONFIG_MGR.write().await.init(store).await
}
#[cfg(test)]