mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-09 14:49:25 +00:00
refactor: centralize ecstore accessor runtime sources (#3813)
This commit is contained in:
@@ -18,8 +18,9 @@ use crate::bucket::bandwidth::monitor::Monitor;
|
||||
use crate::disk::endpoint::Endpoint;
|
||||
use crate::{
|
||||
bucket::lifecycle::bucket_lifecycle_ops::{ExpiryState, GLOBAL_ExpiryState, GLOBAL_TransitionState, TransitionState},
|
||||
bucket::metadata_sys::{BucketMetadataSys, get_global_bucket_metadata_sys},
|
||||
bucket::replication::{DynReplicationPool, GLOBAL_REPLICATION_POOL, GLOBAL_REPLICATION_STATS, ReplicationStats},
|
||||
config::get_global_storage_class,
|
||||
config::{get_global_storage_class, set_global_storage_class, storageclass},
|
||||
disk::{DiskAPI, DiskOption, DiskStore, new_disk},
|
||||
endpoints::EndpointServerPools,
|
||||
error::Result,
|
||||
@@ -28,18 +29,21 @@ use crate::{
|
||||
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_global_bucket_monitor, get_global_deployment_id, get_global_endpoints,
|
||||
get_global_endpoints_opt, get_global_lock_clients, init_global_bucket_monitor, is_dist_erasure, is_erasure,
|
||||
is_first_cluster_node_local, resolve_object_store_handle, set_global_deployment_id,
|
||||
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,
|
||||
},
|
||||
notification_sys::{NotificationSys, get_global_notification_sys},
|
||||
store::ECStore,
|
||||
tier::tier::TierConfigMgr,
|
||||
};
|
||||
use rustfs_common::{GLOBAL_CONN_MAP, GLOBAL_LOCAL_NODE_NAME, GLOBAL_RUSTFS_ADDR};
|
||||
use rustfs_common::{GLOBAL_CONN_MAP, GLOBAL_LOCAL_NODE_NAME, GLOBAL_RUSTFS_ADDR, GLOBAL_RUSTFS_HOST};
|
||||
use rustfs_config::server_config::{Config, get_global_server_config, set_global_server_config};
|
||||
use rustfs_io_metrics::internode_metrics::global_internode_metrics;
|
||||
use rustfs_kms::{ObjectEncryptionService, get_global_encryption_service};
|
||||
use rustfs_lock::client::LockClient;
|
||||
use s3s::dto::BucketLifecycleConfiguration;
|
||||
use s3s::region::Region;
|
||||
use tokio::sync::RwLock;
|
||||
use tonic::transport::Channel;
|
||||
use uuid::Uuid;
|
||||
@@ -95,10 +99,22 @@ pub(crate) async fn local_node_name() -> String {
|
||||
GLOBAL_LOCAL_NODE_NAME.read().await.clone()
|
||||
}
|
||||
|
||||
pub(crate) async fn set_local_node_name(node_name: String) {
|
||||
*GLOBAL_LOCAL_NODE_NAME.write().await = node_name;
|
||||
}
|
||||
|
||||
pub(crate) fn default_local_node_name() -> String {
|
||||
GLOBAL_LocalNodeName.to_string()
|
||||
}
|
||||
|
||||
pub(crate) fn rustfs_port() -> u16 {
|
||||
global_rustfs_port()
|
||||
}
|
||||
|
||||
pub(crate) async fn rustfs_host() -> String {
|
||||
GLOBAL_RUSTFS_HOST.read().await.clone()
|
||||
}
|
||||
|
||||
pub(crate) async fn rustfs_addr() -> String {
|
||||
GLOBAL_RUSTFS_ADDR.read().await.clone()
|
||||
}
|
||||
@@ -186,10 +202,52 @@ pub(crate) fn global_lock_clients() -> Option<&'static HashMap<String, Arc<dyn L
|
||||
get_global_lock_clients()
|
||||
}
|
||||
|
||||
pub(crate) fn set_primary_lock_client(client: Arc<dyn LockClient>) -> std::result::Result<(), Arc<dyn LockClient>> {
|
||||
set_global_lock_client(client)
|
||||
}
|
||||
|
||||
pub(crate) fn set_lock_clients(
|
||||
clients: HashMap<String, Arc<dyn LockClient>>,
|
||||
) -> std::result::Result<(), HashMap<String, Arc<dyn LockClient>>> {
|
||||
set_global_lock_clients(clients)
|
||||
}
|
||||
|
||||
pub(crate) async fn publish_object_store(store: Arc<ECStore>) {
|
||||
set_object_layer(store).await;
|
||||
}
|
||||
|
||||
pub(crate) fn notification_sys() -> Option<&'static NotificationSys> {
|
||||
get_global_notification_sys()
|
||||
}
|
||||
|
||||
pub(crate) fn bucket_metadata_sys() -> Option<Arc<RwLock<BucketMetadataSys>>> {
|
||||
get_global_bucket_metadata_sys()
|
||||
}
|
||||
|
||||
pub(crate) fn region() -> Option<Region> {
|
||||
get_global_region()
|
||||
}
|
||||
|
||||
pub(crate) fn server_config() -> Option<Config> {
|
||||
get_global_server_config()
|
||||
}
|
||||
|
||||
pub(crate) fn set_server_config(config: Config) {
|
||||
set_global_server_config(config);
|
||||
}
|
||||
|
||||
pub(crate) fn storage_class_config() -> Option<storageclass::Config> {
|
||||
get_global_storage_class()
|
||||
}
|
||||
|
||||
pub(crate) fn set_storage_class_config(config: storageclass::Config) {
|
||||
set_global_storage_class(config);
|
||||
}
|
||||
|
||||
pub(crate) fn global_tier_config_mgr() -> Arc<RwLock<TierConfigMgr>> {
|
||||
get_global_tier_config_mgr()
|
||||
}
|
||||
|
||||
pub(crate) async fn bucket_lifecycle_config(bucket: &str) -> Option<BucketLifecycleConfiguration> {
|
||||
GLOBAL_LifecycleSys.get(bucket).await
|
||||
}
|
||||
|
||||
+15
-21
@@ -19,7 +19,6 @@ use crate::bucket::lifecycle::bucket_lifecycle_audit::LcEventSrc;
|
||||
use crate::bucket::lifecycle::bucket_lifecycle_ops::{
|
||||
enqueue_immediate_expiry, enqueue_transition_immediate, init_background_expiry,
|
||||
};
|
||||
use crate::bucket::metadata_sys::get_global_bucket_metadata_sys;
|
||||
use crate::bucket::metadata_sys::{self, set_bucket_metadata};
|
||||
use crate::bucket::utils::check_abort_multipart_args;
|
||||
use crate::bucket::utils::check_complete_multipart_args;
|
||||
@@ -33,7 +32,6 @@ use crate::bucket::utils::check_object_args;
|
||||
use crate::bucket::utils::check_put_object_args;
|
||||
use crate::bucket::utils::check_put_object_part_args;
|
||||
use crate::bucket::utils::{check_valid_bucket_name, check_valid_bucket_name_strict, is_meta_bucketname};
|
||||
use crate::config::get_global_storage_class;
|
||||
use crate::config::storageclass;
|
||||
use crate::disk::endpoint::{Endpoint, EndpointType};
|
||||
use crate::disk::{DiskAPI, DiskInfo, DiskInfoOptions};
|
||||
@@ -43,10 +41,7 @@ use crate::error::{
|
||||
is_err_read_quorum, is_err_version_not_found, to_object_err,
|
||||
};
|
||||
use crate::event_notification::EventNotifier;
|
||||
use crate::global::{
|
||||
DISK_RESERVE_FRACTION, TypeLocalDiskSetDrives, get_global_region, get_global_tier_config_mgr, set_object_layer,
|
||||
};
|
||||
use crate::notification_sys::get_global_notification_sys;
|
||||
use crate::global::{DISK_RESERVE_FRACTION, TypeLocalDiskSetDrives};
|
||||
use crate::pools::PoolMeta;
|
||||
use crate::rebalance::RebalanceMeta;
|
||||
use crate::rpc::RemoteClient;
|
||||
@@ -67,8 +62,7 @@ use http::HeaderMap;
|
||||
use lazy_static::lazy_static;
|
||||
use rand::RngExt as _;
|
||||
use rustfs_common::heal_channel::{HealItemType, HealOpts};
|
||||
use rustfs_common::{GLOBAL_LOCAL_NODE_NAME, GLOBAL_RUSTFS_ADDR, GLOBAL_RUSTFS_HOST, GLOBAL_RUSTFS_PORT};
|
||||
use rustfs_config::server_config::{Config, get_global_server_config, set_global_server_config};
|
||||
use rustfs_config::server_config::Config;
|
||||
use rustfs_filemeta::FileInfo;
|
||||
use rustfs_lock::{LocalClient, LockClient, NamespaceLockWrapper};
|
||||
use rustfs_madmin::heal_commands::HealResultItem;
|
||||
@@ -229,22 +223,22 @@ impl std::fmt::Debug for ECStore {
|
||||
impl ECStore {
|
||||
/// Get server configuration (delegates to global)
|
||||
pub fn get_server_config(&self) -> Option<Config> {
|
||||
get_global_server_config()
|
||||
runtime_sources::server_config()
|
||||
}
|
||||
|
||||
/// Set server configuration (delegates to global)
|
||||
pub fn set_server_config(&self, cfg: Config) {
|
||||
set_global_server_config(cfg);
|
||||
runtime_sources::set_server_config(cfg);
|
||||
}
|
||||
|
||||
/// Get storage class configuration (delegates to global)
|
||||
pub fn get_storage_class(&self) -> Option<crate::config::storageclass::Config> {
|
||||
crate::config::get_global_storage_class()
|
||||
runtime_sources::storage_class_config()
|
||||
}
|
||||
|
||||
/// Set storage class configuration (delegates to global)
|
||||
pub fn set_storage_class(&self, cfg: crate::config::storageclass::Config) {
|
||||
crate::config::set_global_storage_class(cfg);
|
||||
runtime_sources::set_storage_class_config(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,12 +248,12 @@ impl ECStore {
|
||||
impl ECStore {
|
||||
/// Get the notification system
|
||||
pub fn notification_system(&self) -> Option<&'static crate::notification_sys::NotificationSys> {
|
||||
get_global_notification_sys()
|
||||
runtime_sources::notification_sys()
|
||||
}
|
||||
|
||||
/// Get the bucket metadata system
|
||||
pub fn bucket_metadata_sys(&self) -> Option<Arc<tokio::sync::RwLock<crate::bucket::metadata_sys::BucketMetadataSys>>> {
|
||||
get_global_bucket_metadata_sys()
|
||||
runtime_sources::bucket_metadata_sys()
|
||||
}
|
||||
|
||||
/// Get the global endpoints
|
||||
@@ -269,22 +263,22 @@ impl ECStore {
|
||||
|
||||
/// Get the global region
|
||||
pub fn region(&self) -> Option<s3s::region::Region> {
|
||||
get_global_region()
|
||||
runtime_sources::region()
|
||||
}
|
||||
|
||||
/// Get the tier config manager
|
||||
pub fn tier_config_mgr(&self) -> Arc<tokio::sync::RwLock<crate::tier::tier::TierConfigMgr>> {
|
||||
get_global_tier_config_mgr()
|
||||
runtime_sources::global_tier_config_mgr()
|
||||
}
|
||||
|
||||
/// Get the server configuration
|
||||
pub fn server_config(&self) -> Option<Config> {
|
||||
get_global_server_config()
|
||||
runtime_sources::server_config()
|
||||
}
|
||||
|
||||
/// Get the storage class configuration
|
||||
pub fn storage_class(&self) -> Option<crate::config::storageclass::Config> {
|
||||
get_global_storage_class()
|
||||
runtime_sources::storage_class_config()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,17 +288,17 @@ impl ECStore {
|
||||
impl ECStore {
|
||||
/// Get the server port
|
||||
pub fn port(&self) -> u16 {
|
||||
crate::global::global_rustfs_port()
|
||||
runtime_sources::rustfs_port()
|
||||
}
|
||||
|
||||
/// Get the server host
|
||||
pub async fn host(&self) -> String {
|
||||
GLOBAL_RUSTFS_HOST.read().await.clone()
|
||||
runtime_sources::rustfs_host().await
|
||||
}
|
||||
|
||||
/// Get the server address (host:port)
|
||||
pub async fn addr(&self) -> String {
|
||||
GLOBAL_RUSTFS_ADDR.read().await.clone()
|
||||
runtime_sources::rustfs_addr().await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,11 +168,11 @@ impl ECStore {
|
||||
);
|
||||
let mut host = address.ip().to_string();
|
||||
if host.is_empty() {
|
||||
host = GLOBAL_RUSTFS_HOST.read().await.to_string()
|
||||
host = runtime_sources::rustfs_host().await
|
||||
}
|
||||
let mut port = address.port().to_string();
|
||||
if port.is_empty() {
|
||||
port = GLOBAL_RUSTFS_PORT.read().await.to_string()
|
||||
port = runtime_sources::rustfs_port().to_string()
|
||||
}
|
||||
debug!(
|
||||
event = EVENT_ECSTORE_INIT_STATUS,
|
||||
@@ -351,7 +351,7 @@ impl ECStore {
|
||||
break;
|
||||
}
|
||||
|
||||
set_object_layer(ec.clone()).await;
|
||||
runtime_sources::publish_object_store(ec.clone()).await;
|
||||
|
||||
if let Some(monitor) = runtime_sources::bucket_monitor() {
|
||||
let _ = ec.bucket_monitor.set(monitor);
|
||||
|
||||
@@ -113,7 +113,7 @@ pub fn init_lock_clients(endpoint_pools: EndpointServerPools) {
|
||||
|
||||
// Store the first LocalClient globally for use by other modules
|
||||
if !first_local_client_set {
|
||||
if let Err(e) = crate::global::set_global_lock_client(local_client.clone()) {
|
||||
if let Err(e) = runtime_sources::set_primary_lock_client(local_client.clone()) {
|
||||
// If already set, ignore the error (another thread may have set it)
|
||||
debug!(
|
||||
event = EVENT_LOCK_CLIENT_INITIALIZATION_FAILED,
|
||||
@@ -135,7 +135,7 @@ pub fn init_lock_clients(endpoint_pools: EndpointServerPools) {
|
||||
}
|
||||
|
||||
// Store the lock clients map globally
|
||||
if crate::global::set_global_lock_clients(clients).is_err() {
|
||||
if runtime_sources::set_lock_clients(clients).is_err() {
|
||||
error!(
|
||||
event = EVENT_LOCK_CLIENT_INITIALIZATION_FAILED,
|
||||
component = LOG_COMPONENT_ECSTORE,
|
||||
@@ -158,15 +158,15 @@ pub(super) async fn init_local_peer(endpoint_pools: &EndpointServerPools, host:
|
||||
|
||||
if peer_set.is_empty() {
|
||||
if !host.is_empty() {
|
||||
*GLOBAL_LOCAL_NODE_NAME.write().await = format!("{host}:{port}");
|
||||
runtime_sources::set_local_node_name(format!("{host}:{port}")).await;
|
||||
return;
|
||||
}
|
||||
|
||||
*GLOBAL_LOCAL_NODE_NAME.write().await = format!("127.0.0.1:{port}");
|
||||
runtime_sources::set_local_node_name(format!("127.0.0.1:{port}")).await;
|
||||
return;
|
||||
}
|
||||
|
||||
*GLOBAL_LOCAL_NODE_NAME.write().await = peer_set[0].clone();
|
||||
runtime_sources::set_local_node_name(peer_set[0].clone()).await;
|
||||
}
|
||||
|
||||
pub async fn get_disk_infos(disks: &[Option<DiskStore>]) -> Vec<Option<DiskInfo>> {
|
||||
|
||||
Reference in New Issue
Block a user