mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 16:48:58 +00:00
refactor(server): route config access through AppContext (#1960)
Signed-off-by: 安正超 <anzhengchao@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -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<RwLock<TierConfigMgr>>;
|
||||
}
|
||||
|
||||
/// Server config interface for application-layer and server modules.
|
||||
pub trait ServerConfigInterface: Send + Sync {
|
||||
fn get(&self) -> Option<Config>;
|
||||
}
|
||||
|
||||
/// Default IAM interface adapter.
|
||||
pub struct IamHandle {
|
||||
iam: Arc<IamSys<ObjectStore>>,
|
||||
@@ -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<Config> {
|
||||
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<dyn EndpointsInterface>,
|
||||
region: Arc<dyn RegionInterface>,
|
||||
tier_config: Arc<dyn TierConfigInterface>,
|
||||
server_config: Arc<dyn ServerConfigInterface>,
|
||||
}
|
||||
|
||||
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<dyn TierConfigInterface> {
|
||||
self.tier_config.clone()
|
||||
}
|
||||
|
||||
pub fn server_config(&self) -> Arc<dyn ServerConfigInterface> {
|
||||
self.server_config.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_notify_interface() -> Arc<dyn NotifyInterface> {
|
||||
@@ -267,6 +289,10 @@ pub fn default_tier_config_interface() -> Arc<dyn TierConfigInterface> {
|
||||
Arc::new(TierConfigHandle)
|
||||
}
|
||||
|
||||
pub fn default_server_config_interface() -> Arc<dyn ServerConfigInterface> {
|
||||
Arc::new(ServerConfigHandle)
|
||||
}
|
||||
|
||||
static GLOBAL_APP_CONTEXT: OnceLock<Arc<AppContext>> = OnceLock::new();
|
||||
|
||||
/// Initialize global application context once and return the canonical instance.
|
||||
|
||||
@@ -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<rustfs_ecstore::config::Config> {
|
||||
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!(
|
||||
|
||||
@@ -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<rustfs_ecstore::config::Config> {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user