mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-13 00:26:53 +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:
@@ -17,9 +17,10 @@ use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::{
|
||||
GlobalLockManager,
|
||||
client::LockClient,
|
||||
error::Result,
|
||||
fast_lock::{FastLockGuard, FastObjectLockManager},
|
||||
fast_lock::{FastLockGuard, LockManager},
|
||||
types::{LockId, LockInfo, LockMetadata, LockPriority, LockRequest, LockResponse, LockStats, LockType},
|
||||
};
|
||||
|
||||
@@ -37,9 +38,9 @@ impl LocalClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the global fast lock manager
|
||||
pub fn get_fast_lock_manager(&self) -> Arc<FastObjectLockManager> {
|
||||
crate::get_global_fast_lock_manager()
|
||||
/// Get the global lock manager
|
||||
pub fn get_lock_manager(&self) -> Arc<GlobalLockManager> {
|
||||
crate::get_global_lock_manager()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,11 +53,11 @@ impl Default for LocalClient {
|
||||
#[async_trait::async_trait]
|
||||
impl LockClient for LocalClient {
|
||||
async fn acquire_exclusive(&self, request: &LockRequest) -> Result<LockResponse> {
|
||||
let fast_lock_manager = self.get_fast_lock_manager();
|
||||
let lock_manager = self.get_lock_manager();
|
||||
let lock_request = crate::fast_lock::ObjectLockRequest::new_write("", request.resource.clone(), request.owner.clone())
|
||||
.with_acquire_timeout(request.acquire_timeout);
|
||||
|
||||
match fast_lock_manager.acquire_lock(lock_request).await {
|
||||
match lock_manager.acquire_lock(lock_request).await {
|
||||
Ok(guard) => {
|
||||
let lock_id = crate::types::LockId::new_deterministic(&request.resource);
|
||||
|
||||
@@ -96,11 +97,11 @@ impl LockClient for LocalClient {
|
||||
}
|
||||
|
||||
async fn acquire_shared(&self, request: &LockRequest) -> Result<LockResponse> {
|
||||
let fast_lock_manager = self.get_fast_lock_manager();
|
||||
let lock_manager = self.get_lock_manager();
|
||||
let lock_request = crate::fast_lock::ObjectLockRequest::new_read("", request.resource.clone(), request.owner.clone())
|
||||
.with_acquire_timeout(request.acquire_timeout);
|
||||
|
||||
match fast_lock_manager.acquire_lock(lock_request).await {
|
||||
match lock_manager.acquire_lock(lock_request).await {
|
||||
Ok(guard) => {
|
||||
let lock_id = crate::types::LockId::new_deterministic(&request.resource);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user