mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
fix race condition when loading volumes concurrently
This commit is contained in:
parent
200e56215a
commit
4e58a4f24e
|
@ -99,10 +99,9 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -110,11 +109,14 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne
|
||||||
// load the volume
|
// load the volume
|
||||||
v, e := NewVolume(l.Directory, l.IdxDirectory, collection, vid, needleMapKind, nil, nil, 0, 0)
|
v, e := NewVolume(l.Directory, l.IdxDirectory, collection, vid, needleMapKind, nil, nil, 0, 0)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
|
l.volumesLock.Unlock()
|
||||||
glog.V(0).Infof("new volume %s error %s", volumeName, e)
|
glog.V(0).Infof("new volume %s error %s", volumeName, e)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
l.SetVolume(vid, v)
|
l.volumes[vid] = v
|
||||||
|
v.location = l
|
||||||
|
l.volumesLock.Unlock()
|
||||||
|
|
||||||
size, _, _ := v.FileStat()
|
size, _, _ := v.FileStat()
|
||||||
glog.V(0).Infof("data file %s, replicaPlacement=%s v=%d size=%d ttl=%s",
|
glog.V(0).Infof("data file %s, replicaPlacement=%s v=%d size=%d ttl=%s",
|
||||||
|
|
Loading…
Reference in a new issue