From 49579129c146e84994293bfaa15d05ee2e7f440c 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 14:54:45 +0800 Subject: [PATCH] refactor(app): decouple AppContext adapters from GLOBAL statics (#1970) --- crates/ecstore/src/bucket/metadata_sys.rs | 4 ++++ crates/ecstore/src/config/mod.rs | 4 ++++ crates/ecstore/src/global.rs | 8 ++++++++ rustfs/src/app/context.rs | 15 +++++++-------- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/crates/ecstore/src/bucket/metadata_sys.rs b/crates/ecstore/src/bucket/metadata_sys.rs index e10a738ae..95c19d024 100644 --- a/crates/ecstore/src/bucket/metadata_sys.rs +++ b/crates/ecstore/src/bucket/metadata_sys.rs @@ -53,6 +53,10 @@ pub async fn init_bucket_metadata_sys(api: Arc, buckets: Vec) { GLOBAL_BucketMetadataSys.set(sys).unwrap(); } +pub fn get_global_bucket_metadata_sys() -> Option>> { + GLOBAL_BucketMetadataSys.get().cloned() +} + // panic if not init pub(super) fn get_bucket_metadata_sys() -> Result>> { if let Some(sys) = GLOBAL_BucketMetadataSys.get() { diff --git a/crates/ecstore/src/config/mod.rs b/crates/ecstore/src/config/mod.rs index 701050f6d..a7e67c49a 100644 --- a/crates/ecstore/src/config/mod.rs +++ b/crates/ecstore/src/config/mod.rs @@ -67,6 +67,10 @@ impl ConfigSys { } } +pub fn get_global_server_config() -> Option { + GLOBAL_SERVER_CONFIG.get().cloned() +} + #[derive(Debug, Deserialize, Serialize, Clone)] pub struct KV { pub key: String, diff --git a/crates/ecstore/src/global.rs b/crates/ecstore/src/global.rs index f73363e19..65035a061 100644 --- a/crates/ecstore/src/global.rs +++ b/crates/ecstore/src/global.rs @@ -150,6 +150,14 @@ pub fn get_global_endpoints() -> EndpointServerPools { } } +pub fn get_global_endpoints_opt() -> Option { + GLOBAL_Endpoints.get().cloned() +} + +pub fn get_global_tier_config_mgr() -> Arc> { + GLOBAL_TierConfigMgr.clone() +} + /// Create a new object layer instance /// /// # Returns diff --git a/rustfs/src/app/context.rs b/rustfs/src/app/context.rs index e0d106a47..b1df0b866 100644 --- a/rustfs/src/app/context.rs +++ b/rustfs/src/app/context.rs @@ -19,11 +19,10 @@ use crate::config::workload_profiles::{RustFSBufferConfig, get_global_buffer_config}; use async_trait::async_trait; -use rustfs_ecstore::GLOBAL_Endpoints; -use rustfs_ecstore::bucket::metadata_sys::{BucketMetadataSys, GLOBAL_BucketMetadataSys}; -use rustfs_ecstore::config::{Config, GLOBAL_SERVER_CONFIG}; +use rustfs_ecstore::bucket::metadata_sys::{BucketMetadataSys, get_global_bucket_metadata_sys}; +use rustfs_ecstore::config::{Config, get_global_server_config}; use rustfs_ecstore::endpoints::EndpointServerPools; -use rustfs_ecstore::global::get_global_region; +use rustfs_ecstore::global::{get_global_endpoints_opt, get_global_region, get_global_tier_config_mgr}; use rustfs_ecstore::store::ECStore; use rustfs_ecstore::tier::tier::TierConfigMgr; use rustfs_iam::{store::object::ObjectStore, sys::IamSys}; @@ -172,7 +171,7 @@ pub struct BucketMetadataHandle; impl BucketMetadataInterface for BucketMetadataHandle { fn handle(&self) -> Option>> { - GLOBAL_BucketMetadataSys.get().cloned() + get_global_bucket_metadata_sys() } } @@ -182,7 +181,7 @@ pub struct EndpointsHandle; impl EndpointsInterface for EndpointsHandle { fn handle(&self) -> Option { - GLOBAL_Endpoints.get().cloned() + get_global_endpoints_opt() } } @@ -202,7 +201,7 @@ pub struct TierConfigHandle; impl TierConfigInterface for TierConfigHandle { fn handle(&self) -> Arc> { - rustfs_ecstore::global::GLOBAL_TierConfigMgr.clone() + get_global_tier_config_mgr() } } @@ -212,7 +211,7 @@ pub struct ServerConfigHandle; impl ServerConfigInterface for ServerConfigHandle { fn get(&self) -> Option { - GLOBAL_SERVER_CONFIG.get().cloned() + get_global_server_config() } }