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 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-03 15:39:22 -08:00
1 parent 4328129818
commit 5511baae15
2 files changed
+7 -5

No files matched your search

-5
View File
@@ -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
+7
View File
@@ -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)
}