feat(lock): Add support for disabling lock manager (#511)

* feat(lock): Add support for disabling lock manager
Implement control of lock system activation and deactivation via environment variables
Add DisabledLockManager for lock-free operation scenarios
Introduce LockManager trait to uniformly manage different lock managers

Signed-off-by: junxiang Mu <1948535941@qq.com>

* refactor(lock): Optimize implementation of global lock manager and parsing of boolean environment variables
Refactor the implementation of the global lock manager: wrap FastObjectLockManager with Arc and add the as_fast_lock_manager method
Extract the boolean environment variable parsing logic into an independent function parse_bool_env_var

Signed-off-by: junxiang Mu <1948535941@qq.com>

---------

Signed-off-by: junxiang Mu <1948535941@qq.com>
This commit is contained in:
guojidan
2025-09-11 13:46:06 +08:00
committed by GitHub
parent d4beb1cc0b
commit cf863ba059
11 changed files with 1052 additions and 44 deletions
+30
View File
@@ -142,6 +142,20 @@ pub struct MetricsSnapshot {
}
impl MetricsSnapshot {
/// Create empty snapshot (for disabled lock manager)
pub fn empty() -> Self {
Self {
fast_path_success: 0,
slow_path_success: 0,
timeouts: 0,
releases: 0,
cleanups: 0,
contention_events: 0,
total_wait_time_ns: 0,
max_wait_time_ns: 0,
}
}
pub fn total_acquisitions(&self) -> u64 {
self.fast_path_success + self.slow_path_success
}
@@ -251,6 +265,22 @@ pub struct AggregatedMetrics {
}
impl AggregatedMetrics {
/// Create empty metrics (for disabled lock manager)
pub fn empty() -> Self {
Self {
shard_metrics: MetricsSnapshot::empty(),
shard_count: 0,
uptime: Duration::ZERO,
cleanup_runs: 0,
total_objects_cleaned: 0,
}
}
/// Check if metrics are empty (indicates disabled or no activity)
pub fn is_empty(&self) -> bool {
self.shard_count == 0 && self.shard_metrics.total_acquisitions() == 0 && self.shard_metrics.releases == 0
}
/// Get operations per second
pub fn ops_per_second(&self) -> f64 {
let total_ops = self.shard_metrics.total_acquisitions() + self.shard_metrics.releases;