mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-25 05:26:50 +00:00
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:
@@ -18,9 +18,10 @@ use tokio::time::{Instant, interval};
|
||||
|
||||
use crate::fast_lock::{
|
||||
guard::FastLockGuard,
|
||||
metrics::GlobalMetrics,
|
||||
manager_trait::LockManager,
|
||||
metrics::{AggregatedMetrics, GlobalMetrics},
|
||||
shard::LockShard,
|
||||
types::{BatchLockRequest, BatchLockResult, LockConfig, LockResult, ObjectLockRequest},
|
||||
types::{BatchLockRequest, BatchLockResult, LockConfig, LockResult, ObjectKey, ObjectLockInfo, ObjectLockRequest},
|
||||
};
|
||||
|
||||
/// High-performance object lock manager
|
||||
@@ -361,6 +362,87 @@ impl Drop for FastObjectLockManager {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl LockManager for FastObjectLockManager {
|
||||
async fn acquire_lock(&self, request: ObjectLockRequest) -> Result<FastLockGuard, LockResult> {
|
||||
self.acquire_lock(request).await
|
||||
}
|
||||
|
||||
async fn acquire_read_lock(
|
||||
&self,
|
||||
bucket: impl Into<Arc<str>> + Send,
|
||||
object: impl Into<Arc<str>> + Send,
|
||||
owner: impl Into<Arc<str>> + Send,
|
||||
) -> Result<FastLockGuard, LockResult> {
|
||||
self.acquire_read_lock(bucket, object, owner).await
|
||||
}
|
||||
|
||||
async fn acquire_read_lock_versioned(
|
||||
&self,
|
||||
bucket: impl Into<Arc<str>> + Send,
|
||||
object: impl Into<Arc<str>> + Send,
|
||||
version: impl Into<Arc<str>> + Send,
|
||||
owner: impl Into<Arc<str>> + Send,
|
||||
) -> Result<FastLockGuard, LockResult> {
|
||||
self.acquire_read_lock_versioned(bucket, object, version, owner).await
|
||||
}
|
||||
|
||||
async fn acquire_write_lock(
|
||||
&self,
|
||||
bucket: impl Into<Arc<str>> + Send,
|
||||
object: impl Into<Arc<str>> + Send,
|
||||
owner: impl Into<Arc<str>> + Send,
|
||||
) -> Result<FastLockGuard, LockResult> {
|
||||
self.acquire_write_lock(bucket, object, owner).await
|
||||
}
|
||||
|
||||
async fn acquire_write_lock_versioned(
|
||||
&self,
|
||||
bucket: impl Into<Arc<str>> + Send,
|
||||
object: impl Into<Arc<str>> + Send,
|
||||
version: impl Into<Arc<str>> + Send,
|
||||
owner: impl Into<Arc<str>> + Send,
|
||||
) -> Result<FastLockGuard, LockResult> {
|
||||
self.acquire_write_lock_versioned(bucket, object, version, owner).await
|
||||
}
|
||||
|
||||
async fn acquire_locks_batch(&self, batch_request: BatchLockRequest) -> BatchLockResult {
|
||||
self.acquire_locks_batch(batch_request).await
|
||||
}
|
||||
|
||||
fn get_lock_info(&self, key: &ObjectKey) -> Option<ObjectLockInfo> {
|
||||
self.get_lock_info(key)
|
||||
}
|
||||
|
||||
fn get_metrics(&self) -> AggregatedMetrics {
|
||||
self.get_metrics()
|
||||
}
|
||||
|
||||
fn total_lock_count(&self) -> usize {
|
||||
self.total_lock_count()
|
||||
}
|
||||
|
||||
fn get_pool_stats(&self) -> Vec<(u64, u64, u64, usize)> {
|
||||
self.get_pool_stats()
|
||||
}
|
||||
|
||||
async fn cleanup_expired(&self) -> usize {
|
||||
self.cleanup_expired().await
|
||||
}
|
||||
|
||||
async fn cleanup_expired_traditional(&self) -> usize {
|
||||
self.cleanup_expired_traditional().await
|
||||
}
|
||||
|
||||
async fn shutdown(&self) {
|
||||
self.shutdown().await
|
||||
}
|
||||
|
||||
fn is_disabled(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user