mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-08 14:23:13 +00:00
refactor: centralize ecstore setup runtime sources (#3812)
This commit is contained in:
@@ -17,7 +17,8 @@ use std::slice::Iter;
|
||||
use crate::bucket::utils::is_meta_bucketname;
|
||||
use crate::disk::DiskInfo;
|
||||
use crate::error::{Error, Result};
|
||||
use crate::global::{DISK_ASSUME_UNKNOWN_SIZE, DISK_FILL_FRACTION, DISK_MIN_INODES, is_erasure_sd};
|
||||
use crate::global::{DISK_ASSUME_UNKNOWN_SIZE, DISK_FILL_FRACTION, DISK_MIN_INODES};
|
||||
use crate::runtime_sources;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct PoolAvailableSpace {
|
||||
@@ -97,7 +98,7 @@ pub async fn has_space_for(dis: &[Option<DiskInfo>], size: i64) -> Result<bool>
|
||||
let per_disk = size / disks_num as u64;
|
||||
|
||||
for disk in dis.iter().flatten() {
|
||||
if !is_erasure_sd().await && disk.free_inodes < DISK_MIN_INODES && disk.used_inodes > 0 {
|
||||
if !runtime_sources::setup_is_erasure_sd().await && disk.free_inodes < DISK_MIN_INODES && disk.used_inodes > 0 {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ use crate::rpc::client::{TonicInterceptor, gen_tonic_signature_interceptor, node
|
||||
use crate::{
|
||||
disk::disk_store::{get_drive_active_check_interval, get_drive_active_check_timeout},
|
||||
endpoints::EndpointServerPools,
|
||||
global::is_dist_erasure,
|
||||
metrics_realtime::{CollectMetricsOpts, MetricType},
|
||||
runtime_sources,
|
||||
};
|
||||
use rmp_serde::{Deserializer, Serializer};
|
||||
use rustfs_madmin::{
|
||||
@@ -98,7 +98,7 @@ impl PeerRestClient {
|
||||
}
|
||||
}
|
||||
pub async fn new_clients(eps: EndpointServerPools) -> (Vec<Option<Self>>, Vec<Option<Self>>) {
|
||||
if !is_dist_erasure().await {
|
||||
if !runtime_sources::setup_is_dist_erasure().await {
|
||||
return (Vec::new(), Vec::new());
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ 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, 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, init_global_bucket_monitor, is_dist_erasure, is_erasure,
|
||||
is_first_cluster_node_local, resolve_object_store_handle, set_global_deployment_id,
|
||||
},
|
||||
notification_sys::{NotificationSys, get_global_notification_sys},
|
||||
store::ECStore,
|
||||
@@ -38,6 +38,7 @@ use crate::{
|
||||
use rustfs_common::{GLOBAL_CONN_MAP, GLOBAL_LOCAL_NODE_NAME, GLOBAL_RUSTFS_ADDR};
|
||||
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 tokio::sync::RwLock;
|
||||
use tonic::transport::Channel;
|
||||
@@ -59,6 +60,10 @@ pub(crate) fn endpoint_pools() -> Option<EndpointServerPools> {
|
||||
get_global_endpoints_opt()
|
||||
}
|
||||
|
||||
pub(crate) fn endpoint_pools_or_default() -> EndpointServerPools {
|
||||
get_global_endpoints()
|
||||
}
|
||||
|
||||
pub(crate) fn endpoint_erasure_set_count() -> Option<usize> {
|
||||
endpoint_pools().map(|endpoints| endpoints.es_count())
|
||||
}
|
||||
@@ -82,6 +87,10 @@ pub(crate) async fn setup_is_dist_erasure() -> bool {
|
||||
is_dist_erasure().await
|
||||
}
|
||||
|
||||
pub(crate) async fn setup_is_erasure_sd() -> bool {
|
||||
*GLOBAL_IsErasureSD.read().await
|
||||
}
|
||||
|
||||
pub(crate) async fn local_node_name() -> String {
|
||||
GLOBAL_LOCAL_NODE_NAME.read().await.clone()
|
||||
}
|
||||
@@ -102,6 +111,10 @@ pub(crate) fn boot_uptime_secs() -> u64 {
|
||||
.as_secs()
|
||||
}
|
||||
|
||||
pub(crate) async fn ensure_boot_time() {
|
||||
GLOBAL_BOOT_TIME.get_or_init(|| async { SystemTime::now() }).await;
|
||||
}
|
||||
|
||||
pub(crate) async fn scanner_init_time() -> Option<chrono::DateTime<chrono::Utc>> {
|
||||
rustfs_common::get_global_init_time().await
|
||||
}
|
||||
@@ -169,6 +182,10 @@ pub(crate) fn global_lock_manager() -> Arc<rustfs_lock::GlobalLockManager> {
|
||||
rustfs_lock::get_global_lock_manager()
|
||||
}
|
||||
|
||||
pub(crate) fn global_lock_clients() -> Option<&'static HashMap<String, Arc<dyn LockClient>>> {
|
||||
get_global_lock_clients()
|
||||
}
|
||||
|
||||
pub(crate) fn notification_sys() -> Option<&'static NotificationSys> {
|
||||
get_global_notification_sys()
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ use crate::{
|
||||
error::{StorageError, to_object_err},
|
||||
// event::name::EventName,
|
||||
event_notification::{EventArgs, send_event},
|
||||
global::{GLOBAL_LOCAL_DISK_MAP, GLOBAL_LOCAL_DISK_SET_DRIVES, is_dist_erasure},
|
||||
object_api::{GetObjectReader, ObjectInfo, PutObjReader},
|
||||
store_init::{get_format_erasure_in_quorum, load_format_erasure, load_format_erasure_all, save_format_file},
|
||||
};
|
||||
@@ -1767,7 +1766,7 @@ impl rustfs_storage_api::NamespaceLocking for SetDisks {
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
async fn new_ns_lock(&self, bucket: &str, object: &str) -> Result<NamespaceLockWrapper> {
|
||||
let set_lock = if is_dist_erasure().await {
|
||||
let set_lock = if runtime_sources::setup_is_dist_erasure().await {
|
||||
// Calculate quorum based on lockers count (majority)
|
||||
let lockers_count = self.lockers.len();
|
||||
let write_quorum = if lockers_count > 1 { (lockers_count / 2) + 1 } else { 1 };
|
||||
@@ -2250,7 +2249,7 @@ impl rustfs_storage_api::ObjectOperations for SetDisks {
|
||||
let mut _local_batch_guards: Vec<FastLockGuard> = Vec::with_capacity(batch.requests.len());
|
||||
let mut locked_objects = HashSet::new();
|
||||
|
||||
let dist_erasure = is_dist_erasure().await;
|
||||
let dist_erasure = runtime_sources::setup_is_dist_erasure().await;
|
||||
let mut dist_batch_lock_ids = vec![Vec::new(); self.lockers.len()];
|
||||
|
||||
if dist_erasure {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
use super::*;
|
||||
use crate::disk::health_state::DriveMembershipSnapshot;
|
||||
use crate::runtime_sources;
|
||||
|
||||
impl SetDisks {
|
||||
pub(super) fn format_lock_error(&self, bucket: &str, object: &str, mode: &str, err: &LockResult) -> String {
|
||||
@@ -303,12 +304,14 @@ impl SetDisks {
|
||||
new_disk.enable_health_check();
|
||||
|
||||
if new_disk.is_local() {
|
||||
let mut global_local_disk_map = GLOBAL_LOCAL_DISK_MAP.write().await;
|
||||
let local_disk_map = runtime_sources::local_disk_map_handle();
|
||||
let mut global_local_disk_map = local_disk_map.write().await;
|
||||
let path = new_disk.endpoint().to_string();
|
||||
global_local_disk_map.insert(path, Some(new_disk.clone()));
|
||||
|
||||
if is_dist_erasure().await {
|
||||
let mut local_set_drives = GLOBAL_LOCAL_DISK_SET_DRIVES.write().await;
|
||||
if runtime_sources::setup_is_dist_erasure().await {
|
||||
let local_disk_set_drives = runtime_sources::local_disk_set_drives_handle();
|
||||
let mut local_set_drives = local_disk_set_drives.write().await;
|
||||
local_set_drives[self.pool_index][set_idx][disk_idx] = Some(new_disk.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ use crate::{
|
||||
},
|
||||
endpoints::{Endpoints, PoolEndpoints},
|
||||
error::StorageError,
|
||||
global::{get_global_lock_clients, is_dist_erasure},
|
||||
object_api::{GetObjectReader, ObjectInfo, ObjectOptions, PutObjReader},
|
||||
runtime_sources,
|
||||
set_disk::SetDisks,
|
||||
@@ -37,10 +36,7 @@ use futures::{
|
||||
};
|
||||
use http::HeaderMap;
|
||||
use rustfs_common::heal_channel::HealOpts;
|
||||
use rustfs_common::{
|
||||
GLOBAL_LOCAL_NODE_NAME,
|
||||
heal_channel::{DriveState, HealItemType},
|
||||
};
|
||||
use rustfs_common::heal_channel::{DriveState, HealItemType};
|
||||
use rustfs_filemeta::FileInfo;
|
||||
use rustfs_lock::NamespaceLockWrapper;
|
||||
use rustfs_lock::client::LockClient;
|
||||
@@ -109,7 +105,7 @@ impl Sets {
|
||||
let mut disk_set = Vec::with_capacity(set_count);
|
||||
|
||||
// Get lock clients from global storage
|
||||
let lock_clients = get_global_lock_clients();
|
||||
let lock_clients = runtime_sources::global_lock_clients();
|
||||
|
||||
for i in 0..set_count {
|
||||
let mut set_drive = Vec::with_capacity(set_drive_count);
|
||||
@@ -138,7 +134,7 @@ impl Sets {
|
||||
continue;
|
||||
}
|
||||
|
||||
if disk.as_ref().unwrap().is_local() && is_dist_erasure().await {
|
||||
if disk.as_ref().unwrap().is_local() && runtime_sources::setup_is_dist_erasure().await {
|
||||
let local_disk = runtime_sources::local_disk_set_drive(pool_idx, i, j).await;
|
||||
|
||||
if local_disk.is_none() {
|
||||
@@ -172,7 +168,7 @@ impl Sets {
|
||||
|
||||
let lockers = set_lock_clients.values().cloned().collect::<Vec<Arc<dyn LockClient>>>();
|
||||
let set_disks = SetDisks::new(
|
||||
GLOBAL_LOCAL_NODE_NAME.read().await.to_string(),
|
||||
runtime_sources::local_node_name().await,
|
||||
Arc::new(RwLock::new(set_drive)),
|
||||
set_drive_count,
|
||||
parity_count,
|
||||
|
||||
@@ -44,13 +44,13 @@ use crate::error::{
|
||||
};
|
||||
use crate::event_notification::EventNotifier;
|
||||
use crate::global::{
|
||||
DISK_RESERVE_FRACTION, GLOBAL_BOOT_TIME, TypeLocalDiskSetDrives, get_global_endpoints, get_global_region,
|
||||
get_global_tier_config_mgr, set_object_layer,
|
||||
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::pools::PoolMeta;
|
||||
use crate::rebalance::RebalanceMeta;
|
||||
use crate::rpc::RemoteClient;
|
||||
use crate::runtime_sources;
|
||||
use crate::store_init::{check_disk_fatal_errs, ec_drives_no_config};
|
||||
use crate::tier::tier::TierConfigMgr;
|
||||
use crate::{
|
||||
@@ -84,7 +84,6 @@ use rustfs_utils::path::{decode_dir_object, encode_dir_object, path_join_buf};
|
||||
use s3s::dto::{BucketVersioningStatus, ObjectLockConfiguration, ObjectLockEnabled, VersioningConfiguration};
|
||||
use std::net::SocketAddr;
|
||||
use std::process::exit;
|
||||
use std::time::SystemTime;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, OnceLock},
|
||||
@@ -265,7 +264,7 @@ impl ECStore {
|
||||
|
||||
/// Get the global endpoints
|
||||
pub fn endpoints(&self) -> EndpointServerPools {
|
||||
get_global_endpoints()
|
||||
runtime_sources::endpoint_pools().unwrap_or_else(|| Vec::new().into())
|
||||
}
|
||||
|
||||
/// Get the global region
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
use super::*;
|
||||
use crate::error::is_err_decommission_running;
|
||||
use crate::global::{is_dist_erasure, is_first_cluster_node_local};
|
||||
use crate::pools::local_decommission_queue_prefix;
|
||||
use crate::runtime_sources;
|
||||
use tracing::{debug, error, info, warn};
|
||||
@@ -299,7 +298,7 @@ impl ECStore {
|
||||
}
|
||||
|
||||
// Replace the local disk
|
||||
if !is_dist_erasure().await {
|
||||
if !runtime_sources::setup_is_dist_erasure().await {
|
||||
runtime_sources::record_local_disks(local_disks).await;
|
||||
}
|
||||
|
||||
@@ -363,7 +362,7 @@ impl ECStore {
|
||||
|
||||
#[instrument(level = "debug", skip(self, rx))]
|
||||
pub async fn init(self: &Arc<Self>, rx: CancellationToken) -> Result<()> {
|
||||
GLOBAL_BOOT_TIME.get_or_init(|| async { SystemTime::now() }).await;
|
||||
runtime_sources::ensure_boot_time().await;
|
||||
|
||||
let mut meta = PoolMeta::default();
|
||||
resolve_store_init_stage_result(
|
||||
@@ -378,8 +377,8 @@ impl ECStore {
|
||||
"load_pool_meta",
|
||||
)?;
|
||||
let update = meta.validate(self.pools.clone())?;
|
||||
let endpoints = get_global_endpoints();
|
||||
let should_persist_pool_meta = is_first_cluster_node_local().await;
|
||||
let endpoints = runtime_sources::endpoint_pools_or_default();
|
||||
let should_persist_pool_meta = runtime_sources::first_cluster_node_is_local().await;
|
||||
|
||||
let installed_pool_meta = if !update {
|
||||
meta.clone()
|
||||
|
||||
Reference in New Issue
Block a user