diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2020-12-16 07:24:27 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-16 07:24:27 -0800 |
| commit | 8cb67952db822ef232dd2701ce78a5486d54b4ea (patch) | |
| tree | 57bdc8bf85286c0aab2fb4a33eeca946c2c8eefc | |
| parent | 200e56215a4fdc4ec424f05fb975cdc876d7a2b4 (diff) | |
| parent | 45f902a9b7abf907b31f43bb88d2b15e420cbac5 (diff) | |
| download | seaweedfs-8cb67952db822ef232dd2701ce78a5486d54b4ea.tar.xz seaweedfs-8cb67952db822ef232dd2701ce78a5486d54b4ea.zip | |
Merge pull request #1683 from qieqieplus/master
fix race condition when loading volumes concurrently
| -rw-r--r-- | weed/storage/disk_location.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go index 2d4d120af..359d0cec2 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -99,12 +99,14 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne } // avoid loading one volume more than once - l.volumesLock.RLock() - _, found := l.volumes[vid] - l.volumesLock.RUnlock() - if found { + l.volumesLock.Lock() + if _, found := l.volumes[vid]; found { + l.volumesLock.Unlock() glog.V(1).Infof("loaded volume, %v", vid) return true + } else { + l.volumes[vid] = nil + l.volumesLock.Unlock() } // load the volume @@ -113,7 +115,7 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne glog.V(0).Infof("new volume %s error %s", volumeName, e) return false } - + l.SetVolume(vid, v) size, _, _ := v.FileStat() |
