From 5511baae1533aa351dc29dec9f22be5dcad2e805 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 3 Dec 2026 15:39:22 -0800 Subject: [PATCH] volume: claim the volume before Destroy takes its data locks deleteVolumeById checked the compaction flag and only then let Destroy take the data locks, so a commit that claimed the volume in between still made the delete wait out its reload under the volumes lock. CommitCompact claims before it locks, so Destroy now does the same and refuses a claimed volume without waiting; the separate check in deleteVolumeById is no longer needed. Co-Authored-By: Claude Opus 5.5 --- weed/storage/disk_location.go | 5 ----- weed/storage/volume_write.go | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go index 701b268a83..6c24337677 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -582,11 +582,6 @@ func (l *DiskLocation) deleteVolumeById(vid needle.VolumeId, onlyEmpty bool, onl if !ok { return } - // Destroy would wait out a compaction commit under the volumes lock. - if v.isCompactionInProgress.Load() { - e = v.compactingError() - return - } e = v.Destroy(onlyEmpty, onlyGarbage, keepRemoteData) if e != nil { return diff --git a/weed/storage/volume_write.go b/weed/storage/volume_write.go index 22e9d94d23..e636bf8393 100644 --- a/weed/storage/volume_write.go +++ b/weed/storage/volume_write.go @@ -48,10 +48,17 @@ var ErrVolumeNotEmpty = fmt.Errorf("volume not empty") // true the cloud-tier object backing the volume is left intact — used by // moves where another server is taking over the same .vif. func (v *Volume) Destroy(onlyEmpty bool, onlyGarbage bool, keepRemoteData bool) (err error) { + // A compaction commit claims the volume before it takes these locks and + // holds them across its reload; claiming first refuses it instead of + // waiting it out under the location's volumes lock. + if !v.isCompactionInProgress.CompareAndSwap(false, true) { + return v.compactingError() + } v.dataFileSyncLock.Lock() defer v.dataFileSyncLock.Unlock() v.dataFileAccessLock.Lock() defer v.dataFileAccessLock.Unlock() + v.isCompactionInProgress.Store(false) return v.destroyLocked(onlyEmpty, onlyGarbage, keepRemoteData) }