fix(ecstore): tolerate OnceLock re-initialization in tests (#4074)

This commit is contained in:
Zhengchao An
2026-06-30 00:18:28 +08:00
committed by GitHub
parent c17df6e3d3
commit f401a4388e
2 changed files with 19 additions and 5 deletions
+3 -1
View File
@@ -208,7 +208,9 @@ pub fn resolve_object_store_handle() -> Option<Arc<ECStore>> {
/// # Returns
/// * None
pub async fn set_object_layer(o: Arc<ECStore>) {
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
+16 -4
View File
@@ -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<bool> = 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<bool> = 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.