diff options
| author | 柏杰 <2063169+bai-jie@users.noreply.github.com> | 2023-06-15 05:39:58 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-14 14:39:58 -0700 |
| commit | 0b0fb9b9e4835265abf71e0b0f384fe9bbfce3ea (patch) | |
| tree | 25ad4e2a258b03c0a8d5080ff6431de3000795e9 /weed/storage/disk_location.go | |
| parent | 1e22d5caf2f34df5886b464f16948a294d429657 (diff) | |
| download | seaweedfs-0b0fb9b9e4835265abf71e0b0f384fe9bbfce3ea.tar.xz seaweedfs-0b0fb9b9e4835265abf71e0b0f384fe9bbfce3ea.zip | |
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`
Diffstat (limited to 'weed/storage/disk_location.go')
| -rw-r--r-- | weed/storage/disk_location.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go index 0629acff7..2ee1548a2 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -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 } |
