avoid data race read volume.IsEmpty (#4574)

* avoid data race read volume.IsEmpty

-   avoid phantom read isEmpty for onlyEmpty
-   use `v.DataBackend.GetStat()` in v.dataFileAccessLock scope

* add Destroy(onlyEmpty: true) test

* add Destroy(onlyEmpty: false) test

* remove unused `IsEmpty()`

* change literal `8` to `SuperBlockSize`
This commit is contained in:
柏杰
2023-06-15 05:39:58 +08:00
committed by GitHub
parent 1e22d5caf2
commit 0b0fb9b9e4
7 changed files with 164 additions and 18 deletions

View File

@@ -245,7 +245,7 @@ func (l *DiskLocation) DeleteCollectionFromDiskLocation(collection string) (e er
wg.Add(2)
go func() {
for _, v := range delVolsMap {
if err := v.Destroy(); err != nil {
if err := v.Destroy(false); err != nil {
errChain <- err
}
}
@@ -276,12 +276,12 @@ func (l *DiskLocation) DeleteCollectionFromDiskLocation(collection string) (e er
return
}
func (l *DiskLocation) deleteVolumeById(vid needle.VolumeId) (found bool, e error) {
func (l *DiskLocation) deleteVolumeById(vid needle.VolumeId, onlyEmpty bool) (found bool, e error) {
v, ok := l.volumes[vid]
if !ok {
return
}
e = v.Destroy()
e = v.Destroy(onlyEmpty)
if e != nil {
return
}
@@ -299,7 +299,7 @@ func (l *DiskLocation) LoadVolume(vid needle.VolumeId, needleMapKind NeedleMapKi
var ErrVolumeNotFound = fmt.Errorf("volume not found")
func (l *DiskLocation) DeleteVolume(vid needle.VolumeId) error {
func (l *DiskLocation) DeleteVolume(vid needle.VolumeId, onlyEmpty bool) error {
l.volumesLock.Lock()
defer l.volumesLock.Unlock()
@@ -307,7 +307,7 @@ func (l *DiskLocation) DeleteVolume(vid needle.VolumeId) error {
if !ok {
return ErrVolumeNotFound
}
_, err := l.deleteVolumeById(vid)
_, err := l.deleteVolumeById(vid, onlyEmpty)
return err
}