use two flags: v.isCompacting and v.isCommitCompacting

This commit is contained in:
chrislu 2022-04-26 23:28:34 -07:00
parent b557faf175
commit 37ab8909b0
4 changed files with 6 additions and 5 deletions

View File

@ -283,7 +283,7 @@ func (l *DiskLocation) UnloadVolume(vid needle.VolumeId) error {
func (l *DiskLocation) unmountVolumeByCollection(collectionName string) map[needle.VolumeId]*Volume { func (l *DiskLocation) unmountVolumeByCollection(collectionName string) map[needle.VolumeId]*Volume {
deltaVols := make(map[needle.VolumeId]*Volume, 0) deltaVols := make(map[needle.VolumeId]*Volume, 0)
for k, v := range l.volumes { for k, v := range l.volumes {
if v.Collection == collectionName && !v.isCompacting { if v.Collection == collectionName && !v.isCompacting && !v.isCommitCompacting {
deltaVols[k] = v deltaVols[k] = v
} }
} }

View File

@ -42,7 +42,8 @@ type Volume struct {
lastCompactIndexOffset uint64 lastCompactIndexOffset uint64
lastCompactRevision uint16 lastCompactRevision uint16
isCompacting bool isCompacting bool
isCommitCompacting bool
volumeInfo *volume_server_pb.VolumeInfo volumeInfo *volume_server_pb.VolumeInfo
location *DiskLocation location *DiskLocation

View File

@ -94,9 +94,9 @@ func (v *Volume) CommitCompact() error {
} }
glog.V(0).Infof("Committing volume %d vacuuming...", v.Id) glog.V(0).Infof("Committing volume %d vacuuming...", v.Id)
v.isCompacting = true v.isCommitCompacting = true
defer func() { defer func() {
v.isCompacting = false v.isCommitCompacting = false
}() }()
v.dataFileAccessLock.Lock() v.dataFileAccessLock.Lock()

View File

@ -54,7 +54,7 @@ func (v *Volume) isFileUnchanged(n *needle.Needle) bool {
// Destroy removes everything related to this volume // Destroy removes everything related to this volume
func (v *Volume) Destroy() (err error) { func (v *Volume) Destroy() (err error) {
if v.isCompacting { if v.isCompacting || v.isCommitCompacting {
err = fmt.Errorf("volume %d is compacting", v.Id) err = fmt.Errorf("volume %d is compacting", v.Id)
return return
} }