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) }