mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-10 15:16:56 +00:00
Add env variable alias compatibility warnings (#2044)
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
// limitations under the License.
|
||||
|
||||
//! Disabled lock manager that bypasses all locking operations
|
||||
//! Used when RUSTFS_ENABLE_LOCKS environment variable is set to false
|
||||
//! Used when the lock feature is disabled via RUSTFS_LOCK_ENABLED
|
||||
//! (or deprecated RUSTFS_ENABLE_LOCKS).
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
|
||||
+25
-5
@@ -69,8 +69,12 @@ pub const BUILD_TIMESTAMP: &str = "unknown";
|
||||
/// Maximum number of items in delete list
|
||||
pub const MAX_DELETE_LIST: usize = 1000;
|
||||
|
||||
/// Default setting for RUSTFS_ENABLE_LOCKS environment variable
|
||||
/// Default setting for lock enablement.
|
||||
/// Canonical variable: RUSTFS_LOCK_ENABLED
|
||||
/// Deprecated compatibility alias: RUSTFS_ENABLE_LOCKS
|
||||
const DEFAULT_RUSTFS_LOCKS_ENABLED: bool = true;
|
||||
const ENV_LOCK_ENABLED: &str = "RUSTFS_LOCK_ENABLED";
|
||||
const ENV_LOCK_ENABLED_DEPRECATED: &str = "RUSTFS_ENABLE_LOCKS";
|
||||
|
||||
// ============================================================================
|
||||
// Global FastLock Manager
|
||||
@@ -97,10 +101,26 @@ impl Default for GlobalLockManager {
|
||||
impl GlobalLockManager {
|
||||
/// Create a lock manager based on environment variable configuration
|
||||
pub fn new() -> Self {
|
||||
// Check RUSTFS_ENABLE_LOCKS environment variable
|
||||
let locks_enabled = rustfs_utils::get_env_bool("RUSTFS_ENABLE_LOCKS", DEFAULT_RUSTFS_LOCKS_ENABLED);
|
||||
// Check lock enablement env vars with deprecated compatibility support.
|
||||
let locks_enabled = rustfs_utils::get_env_bool_with_aliases(
|
||||
ENV_LOCK_ENABLED,
|
||||
&[ENV_LOCK_ENABLED_DEPRECATED],
|
||||
DEFAULT_RUSTFS_LOCKS_ENABLED,
|
||||
);
|
||||
if !locks_enabled {
|
||||
tracing::info!("Lock system disabled via RUSTFS_ENABLE_LOCKS environment variable");
|
||||
let disabled_by = if std::env::var(ENV_LOCK_ENABLED).is_ok() {
|
||||
ENV_LOCK_ENABLED
|
||||
} else if std::env::var(ENV_LOCK_ENABLED_DEPRECATED).is_ok() {
|
||||
ENV_LOCK_ENABLED_DEPRECATED
|
||||
} else {
|
||||
"default setting"
|
||||
};
|
||||
|
||||
if disabled_by == "default setting" {
|
||||
tracing::info!("Lock system disabled via default setting");
|
||||
} else {
|
||||
tracing::info!("Lock system disabled via {} environment variable", disabled_by);
|
||||
}
|
||||
return Self::Disabled(DisabledLockManager::new());
|
||||
}
|
||||
tracing::info!("Lock system enabled");
|
||||
@@ -248,7 +268,7 @@ static GLOBAL_LOCK_MANAGER: OnceLock<Arc<GlobalLockManager>> = OnceLock::new();
|
||||
/// Get the global shared lock manager instance
|
||||
///
|
||||
/// Returns either FastObjectLockManager or DisabledLockManager based on
|
||||
/// the RUSTFS_ENABLE_LOCKS environment variable.
|
||||
/// the RUSTFS_LOCK_ENABLED environment variable.
|
||||
pub fn get_global_lock_manager() -> Arc<GlobalLockManager> {
|
||||
GLOBAL_LOCK_MANAGER.get_or_init(|| Arc::new(GlobalLockManager::new())).clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user