use lazy_static::lazy_static; use std::{ collections::HashMap, sync::{Arc, OnceLock}, }; use tokio::sync::RwLock; use uuid::Uuid; use crate::heal::mrf::MRFState; use crate::{ disk::DiskStore, endpoints::{EndpointServerPools, PoolEndpoints, SetupType}, heal::{background_heal_ops::HealRoutine, heal_ops::AllHealState}, store::ECStore, }; pub const DISK_ASSUME_UNKNOWN_SIZE: u64 = 1 << 30; pub const DISK_MIN_INODES: u64 = 1000; pub const DISK_FILL_FRACTION: f64 = 0.99; pub const DISK_RESERVE_FRACTION: f64 = 0.15; pub const DEFAULT_PORT: u16 = 9000; lazy_static! { static ref GLOBAL_RUSTFS_PORT: OnceLock = OnceLock::new(); pub static ref GLOBAL_OBJECT_API: OnceLock> = OnceLock::new(); pub static ref GLOBAL_LOCAL_DISK: Arc>>> = Arc::new(RwLock::new(Vec::new())); pub static ref GLOBAL_IsErasure: RwLock = RwLock::new(false); pub static ref GLOBAL_IsDistErasure: RwLock = RwLock::new(false); pub static ref GLOBAL_IsErasureSD: RwLock = RwLock::new(false); pub static ref GLOBAL_LOCAL_DISK_MAP: Arc>>> = Arc::new(RwLock::new(HashMap::new())); pub static ref GLOBAL_LOCAL_DISK_SET_DRIVES: Arc> = Arc::new(RwLock::new(Vec::new())); pub static ref GLOBAL_Endpoints: OnceLock = OnceLock::new(); pub static ref GLOBAL_RootDiskThreshold: RwLock = RwLock::new(0); pub static ref GLOBAL_BackgroundHealRoutine: Arc = HealRoutine::new(); pub static ref GLOBAL_BackgroundHealState: Arc = AllHealState::new(false); pub static ref GLOBAL_ALlHealState: Arc = AllHealState::new(false); pub static ref GLOBAL_MRFState: Arc = Arc::new(MRFState::new()); static ref globalDeploymentIDPtr: OnceLock = OnceLock::new(); } pub fn global_rustfs_port() -> u16 { if let Some(p) = GLOBAL_RUSTFS_PORT.get() { *p } else { DEFAULT_PORT } } pub fn set_global_rustfs_port(value: u16) { GLOBAL_RUSTFS_PORT.set(value).expect("set_global_rustfs_port fail"); } pub fn set_global_deployment_id(id: Uuid) { globalDeploymentIDPtr.set(id).unwrap(); } pub fn get_global_deployment_id() -> Option { globalDeploymentIDPtr.get().map(|v| v.to_string()) } pub fn set_global_endpoints(eps: Vec) { GLOBAL_Endpoints .set(EndpointServerPools::from(eps)) .expect("GLOBAL_Endpoints set faild") } pub fn get_global_endpoints() -> EndpointServerPools { if let Some(eps) = GLOBAL_Endpoints.get() { eps.clone() } else { EndpointServerPools::default() } } pub fn new_object_layer_fn() -> Option> { GLOBAL_OBJECT_API.get().cloned() } pub async fn set_object_layer(o: Arc) { GLOBAL_OBJECT_API.set(o).expect("set_object_layer fail ") } pub async fn is_dist_erasure() -> bool { let lock = GLOBAL_IsDistErasure.read().await; *lock } pub async fn is_erasure_sd() -> bool { let lock = GLOBAL_IsErasureSD.read().await; *lock } pub async fn is_erasure() -> bool { let lock = GLOBAL_IsErasure.read().await; *lock } pub async fn update_erasure_type(setup_type: SetupType) { let mut is_erasure = GLOBAL_IsErasure.write().await; *is_erasure = setup_type == SetupType::Erasure; let mut is_dist_erasure = GLOBAL_IsDistErasure.write().await; *is_dist_erasure = setup_type == SetupType::DistErasure; if *is_dist_erasure { *is_erasure = true } let mut is_erasure_sd = GLOBAL_IsErasureSD.write().await; *is_erasure_sd = setup_type == SetupType::ErasureSD; } // pub fn is_legacy() -> bool { // if let Some(endpoints) = GLOBAL_Endpoints.get() { // endpoints.as_ref().len() == 1 && endpoints.as_ref()[0].legacy // } else { // false // } // } type TypeLocalDiskSetDrives = Vec>>>;