From acdefb670324ded847169cc30bd18822d10d09ed Mon Sep 17 00:00:00 2001 From: weisd Date: Sun, 16 Nov 2025 11:44:13 +0800 Subject: [PATCH] fix read lock (#866) --- crates/ecstore/src/set_disk.rs | 15 +++++++++++++-- crates/ecstore/src/sets.rs | 7 ++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/ecstore/src/set_disk.rs b/crates/ecstore/src/set_disk.rs index dfb66afe..d242c0e4 100644 --- a/crates/ecstore/src/set_disk.rs +++ b/crates/ecstore/src/set_disk.rs @@ -3545,7 +3545,7 @@ impl ObjectIO for SetDisks { opts: &ObjectOptions, ) -> Result { // Acquire a shared read-lock early to protect read consistency - let _read_lock_guard = if !opts.no_lock { + let read_lock_guard = if !opts.no_lock { Some( self.fast_lock_manager .acquire_read_lock(bucket, object, self.locker_owner.as_str()) @@ -3607,7 +3607,7 @@ impl ObjectIO for SetDisks { // Move the read-lock guard into the task so it lives for the duration of the read // let _guard_to_hold = _read_lock_guard; // moved into closure below tokio::spawn(async move { - // let _guard = _guard_to_hold; // keep guard alive until task ends + let _guard = read_lock_guard; // keep guard alive until task ends let mut writer = wd; if let Err(e) = Self::get_object_with_fileinfo( &bucket, @@ -5534,6 +5534,17 @@ impl StorageAPI for SetDisks { uploaded_parts: Vec, opts: &ObjectOptions, ) -> Result { + let _object_lock_guard = if !opts.no_lock { + Some( + self.fast_lock_manager + .acquire_write_lock(bucket, object, self.locker_owner.as_str()) + .await + .map_err(|e| Error::other(self.format_lock_error(bucket, object, "write", &e)))?, + ) + } else { + None + }; + let (mut fi, files_metas) = self.check_upload_id_exists(bucket, object, upload_id, true).await?; let upload_id_path = Self::get_upload_id_dir(bucket, object, upload_id); diff --git a/crates/ecstore/src/sets.rs b/crates/ecstore/src/sets.rs index e4d5551a..51c92560 100644 --- a/crates/ecstore/src/sets.rs +++ b/crates/ecstore/src/sets.rs @@ -111,6 +111,9 @@ impl Sets { let mut disk_set = Vec::with_capacity(set_count); + // Create fast lock manager for high performance + let fast_lock_manager = Arc::new(rustfs_lock::FastObjectLockManager::new()); + for i in 0..set_count { let mut set_drive = Vec::with_capacity(set_drive_count); let mut set_endpoints = Vec::with_capacity(set_drive_count); @@ -164,11 +167,9 @@ impl Sets { // Note: write_quorum was used for the old lock system, no longer needed with FastLock let _write_quorum = set_drive_count - parity_count; - // Create fast lock manager for high performance - let fast_lock_manager = Arc::new(rustfs_lock::FastObjectLockManager::new()); let set_disks = SetDisks::new( - fast_lock_manager, + fast_lock_manager.clone(), GLOBAL_Local_Node_Name.read().await.to_string(), Arc::new(RwLock::new(set_drive)), set_drive_count,