refactor(lock): restructure lock crate, remove unused modules and clarify directory layout

- Remove unused core/rwlock.rs and manager/ modules (ManagerFactory, LifecycleManager, NamespaceManager)
- Move all lock-related code into crates/lock/src with clear submodules: client, core, utils, etc.
- Ensure only necessary files and APIs are exposed, improve maintainability
- No functional logic change, pure structure and cleanup refactor

Signed-off-by: dandan <dandan@dandandeMac-Studio.local>
This commit is contained in:
dandan
2025-07-04 17:28:18 +08:00
committed by junxiang Mu
parent 1b48934f47
commit 4ccdeb9d2a
28 changed files with 6191 additions and 2466 deletions
+32 -33
View File
@@ -83,7 +83,7 @@ use rustfs_filemeta::{
headers::{AMZ_OBJECT_TAGGING, AMZ_STORAGE_CLASS},
merge_file_meta_versions,
};
use rustfs_lock::{LockApi, namespace_lock::NsLockMap};
use rustfs_lock::{LockApi, NsLockMap};
use rustfs_madmin::heal_commands::{HealDriveInfo, HealResultItem};
use rustfs_rio::{EtagResolvable, HashReader, TryGetIndex as _, WarpReader};
use rustfs_utils::{
@@ -121,11 +121,11 @@ use uuid::Uuid;
pub const DEFAULT_READ_BUFFER_SIZE: usize = 1024 * 1024;
pub const MAX_PARTS_COUNT: usize = 10000;
#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub struct SetDisks {
pub lockers: Vec<LockApi>,
pub locker_owner: String,
pub ns_mutex: Arc<RwLock<NsLockMap>>,
pub ns_mutex: Arc<NsLockMap>,
pub disks: Arc<RwLock<Vec<Option<DiskStore>>>>,
pub set_endpoints: Vec<Endpoint>,
pub set_drive_count: usize,
@@ -140,7 +140,7 @@ impl SetDisks {
pub async fn new(
lockers: Vec<LockApi>,
locker_owner: String,
ns_mutex: Arc<RwLock<NsLockMap>>,
ns_mutex: Arc<NsLockMap>,
disks: Arc<RwLock<Vec<Option<DiskStore>>>>,
set_drive_count: usize,
default_parity_count: usize,
@@ -4066,33 +4066,28 @@ impl ObjectIO for SetDisks {
async fn put_object(&self, bucket: &str, object: &str, data: &mut PutObjReader, opts: &ObjectOptions) -> Result<ObjectInfo> {
let disks = self.disks.read().await;
// let mut _ns = None;
// if !opts.no_lock {
// let paths = vec![object.to_string()];
// let ns_lock = new_nslock(
// Arc::clone(&self.ns_mutex),
// self.locker_owner.clone(),
// bucket.to_string(),
// paths,
// self.lockers.clone(),
// )
// .await;
// if !ns_lock
// .0
// .write()
// .await
// .get_lock(&Options {
// timeout: Duration::from_secs(5),
// retry_interval: Duration::from_secs(1),
// })
// .await
// .map_err(|err| Error::other(err.to_string()))?
// {
// return Err(Error::other("can not get lock. please retry".to_string()));
// }
// 获取对象锁
let mut _ns = None;
if !opts.no_lock {
let paths = vec![object.to_string()];
let ns_lock = self
.ns_mutex
.new_nslock(None)
.await
.map_err(|err| Error::other(err.to_string()))?;
// _ns = Some(ns_lock);
// }
// 尝试获取锁
let lock_acquired = ns_lock
.lock_batch(&paths, &self.locker_owner, std::time::Duration::from_secs(5))
.await
.map_err(|err| Error::other(err.to_string()))?;
if !lock_acquired {
return Err(Error::other("can not get lock. please retry".to_string()));
}
_ns = Some(ns_lock);
}
let mut user_defined = opts.user_defined.clone();
@@ -4298,9 +4293,13 @@ impl ObjectIO for SetDisks {
self.delete_all(RUSTFS_META_TMP_BUCKET, &tmp_dir).await?;
// if let Some(mut locker) = ns {
// locker.un_lock().await.map_err(|err| Error::other(err.to_string()))?;
// }
// 释放对象锁
if let Some(ns_lock) = _ns {
let paths = vec![object.to_string()];
if let Err(err) = ns_lock.unlock_batch(&paths, &self.locker_owner).await {
error!("Failed to unlock object {}: {}", object, err);
}
}
for (i, op_disk) in online_disks.iter().enumerate() {
if let Some(disk) = op_disk {