diff --git a/crates/ecstore/src/runtime/global.rs b/crates/ecstore/src/runtime/global.rs index 5d59f9ea7..bf8cb86d4 100644 --- a/crates/ecstore/src/runtime/global.rs +++ b/crates/ecstore/src/runtime/global.rs @@ -208,7 +208,9 @@ pub fn resolve_object_store_handle() -> Option> { /// # Returns /// * None pub async fn set_object_layer(o: Arc) { - GLOBAL_OBJECT_API.set(o).expect("set_object_layer fail ") + if GLOBAL_OBJECT_API.set(o).is_err() { + warn!("global object layer already initialized, ignoring re-initialization"); + } } /// Check if the setup type is distributed erasure coding diff --git a/crates/ecstore/src/set_disk/mod.rs b/crates/ecstore/src/set_disk/mod.rs index 3e4abff7c..f5e68a804 100644 --- a/crates/ecstore/src/set_disk/mod.rs +++ b/crates/ecstore/src/set_disk/mod.rs @@ -420,15 +420,27 @@ pub fn get_object_lock_diag_slow_hold_threshold() -> Duration { /// When enabled, read locks are released after metadata read instead of /// being held for the entire data transfer duration. /// -/// **Note**: Cached via `OnceLock` — env var changes require process restart. +/// **Note**: Cached via `OnceLock` in production — env var changes require +/// process restart. In test builds the env var is read directly so that +/// `temp_env` overrides take effect. pub fn is_lock_optimization_enabled() -> bool { - static CACHED: OnceLock = OnceLock::new(); - *CACHED.get_or_init(|| { + #[cfg(test)] + { rustfs_utils::get_env_bool( rustfs_config::ENV_OBJECT_LOCK_OPTIMIZATION_ENABLE, rustfs_config::DEFAULT_OBJECT_LOCK_OPTIMIZATION_ENABLE, ) - }) + } + #[cfg(not(test))] + { + static CACHED: OnceLock = OnceLock::new(); + *CACHED.get_or_init(|| { + rustfs_utils::get_env_bool( + rustfs_config::ENV_OBJECT_LOCK_OPTIMIZATION_ENABLE, + rustfs_config::DEFAULT_OBJECT_LOCK_OPTIMIZATION_ENABLE, + ) + }) + } } /// Check if deadlock detection is enabled.