Merge pull request #1683 from qieqieplus/master

fix race condition when loading volumes concurrently
This commit is contained in:
Chris Lu
2020-12-16 07:24:27 -08:00
committed by GitHub

View File

@@ -99,12 +99,14 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne
} }
// avoid loading one volume more than once // avoid loading one volume more than once
l.volumesLock.RLock() l.volumesLock.Lock()
_, found := l.volumes[vid] if _, found := l.volumes[vid]; found {
l.volumesLock.RUnlock() l.volumesLock.Unlock()
if found {
glog.V(1).Infof("loaded volume, %v", vid) glog.V(1).Infof("loaded volume, %v", vid)
return true return true
} else {
l.volumes[vid] = nil
l.volumesLock.Unlock()
} }
// load the volume // load the volume