mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-28 09:08:58 +00:00
fix(ecstore): tolerate OnceLock re-initialization in tests (#4074)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user