diff --git a/rustfs/src/app/context.rs b/rustfs/src/app/context.rs index 87a18e98f..4583034a4 100644 --- a/rustfs/src/app/context.rs +++ b/rustfs/src/app/context.rs @@ -20,6 +20,7 @@ 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::endpoints::EndpointServerPools; use rustfs_ecstore::global::get_global_region; use rustfs_ecstore::store::ECStore; @@ -77,6 +78,11 @@ pub trait TierConfigInterface: Send + Sync { fn handle(&self) -> Arc>; } +/// Server config interface for application-layer and server modules. +pub trait ServerConfigInterface: Send + Sync { + fn get(&self) -> Option; +} + /// Default IAM interface adapter. pub struct IamHandle { iam: Arc>, @@ -179,6 +185,16 @@ impl TierConfigInterface for TierConfigHandle { } } +/// Default server config interface adapter. +#[derive(Default)] +pub struct ServerConfigHandle; + +impl ServerConfigInterface for ServerConfigHandle { + fn get(&self) -> Option { + GLOBAL_SERVER_CONFIG.get().cloned() + } +} + /// Application-layer context with explicit dependencies. #[derive(Clone)] pub struct AppContext { @@ -190,6 +206,7 @@ pub struct AppContext { endpoints: Arc, region: Arc, tier_config: Arc, + server_config: Arc, } impl AppContext { @@ -203,6 +220,7 @@ impl AppContext { endpoints: default_endpoints_interface(), region: default_region_interface(), tier_config: default_tier_config_interface(), + server_config: default_server_config_interface(), } } @@ -245,6 +263,10 @@ impl AppContext { pub fn tier_config(&self) -> Arc { self.tier_config.clone() } + + pub fn server_config(&self) -> Arc { + self.server_config.clone() + } } pub fn default_notify_interface() -> Arc { @@ -267,6 +289,10 @@ pub fn default_tier_config_interface() -> Arc { Arc::new(TierConfigHandle) } +pub fn default_server_config_interface() -> Arc { + Arc::new(ServerConfigHandle) +} + static GLOBAL_APP_CONTEXT: OnceLock> = OnceLock::new(); /// Initialize global application context once and return the canonical instance. diff --git a/rustfs/src/server/audit.rs b/rustfs/src/server/audit.rs index baa6cf569..c423ae087 100644 --- a/rustfs/src/server/audit.rs +++ b/rustfs/src/server/audit.rs @@ -12,11 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. +use crate::app::context::{default_server_config_interface, get_global_app_context}; use rustfs_audit::{AuditError, AuditResult, audit_system, init_audit_system, system::AuditSystemState}; use rustfs_config::DEFAULT_DELIMITER; -use rustfs_ecstore::config::GLOBAL_SERVER_CONFIG; use tracing::{info, warn}; +fn server_config_from_context() -> Option { + match get_global_app_context() { + Some(context) => context.server_config().get(), + None => default_server_config_interface().get(), + } +} + /// Start the audit system. /// This function checks if the audit subsystem is configured in the global server configuration. /// If configured, it initializes and starts the audit system. @@ -29,13 +36,13 @@ pub(crate) async fn start_audit_system() -> AuditResult<()> { ); // 1. Get the global configuration loaded by ecstore - let server_config = match GLOBAL_SERVER_CONFIG.get() { + let server_config = match server_config_from_context() { Some(config) => { info!( target: "rustfs::main::start_audit_system", "Global server configuration loads successfully: {:?}", config ); - config.clone() + config } None => { warn!( diff --git a/rustfs/src/server/event.rs b/rustfs/src/server/event.rs index 9103fb8f9..a3a22720d 100644 --- a/rustfs/src/server/event.rs +++ b/rustfs/src/server/event.rs @@ -12,10 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. +use crate::app::context::{default_server_config_interface, get_global_app_context}; use rustfs_config::DEFAULT_DELIMITER; -use rustfs_ecstore::config::GLOBAL_SERVER_CONFIG; use tracing::{error, info, instrument, warn}; +fn server_config_from_context() -> Option { + match get_global_app_context() { + Some(context) => context.server_config().get(), + None => default_server_config_interface().get(), + } +} + /// Shuts down the event notifier system gracefully pub(crate) async fn shutdown_event_notifier() { info!("Shutting down event notifier system..."); @@ -46,8 +53,8 @@ pub(crate) async fn init_event_notifier() { ); // 1. Get the global configuration loaded by ecstore - let server_config = match GLOBAL_SERVER_CONFIG.get() { - Some(config) => config.clone(), // Clone the config to pass ownership + let server_config = match server_config_from_context() { + Some(config) => config, None => { warn!("Event notifier initialization failed: Global server config not loaded."); return;