diff options
| author | chenqieqie <chenqieqie@gmail.com> | 2020-12-16 18:49:10 +0800 |
|---|---|---|
| committer | chenqieqie <chenqieqie@gmail.com> | 2020-12-16 18:49:10 +0800 |
| commit | 4e58a4f24e6fe489b890c82d08e98a30b0bbc076 (patch) | |
| tree | 64404828d56438aa4d3b9c54131f1af875b37d0e /weed/storage/disk_location.go | |
| parent | 200e56215a4fdc4ec424f05fb975cdc876d7a2b4 (diff) | |
| download | seaweedfs-4e58a4f24e6fe489b890c82d08e98a30b0bbc076.tar.xz seaweedfs-4e58a4f24e6fe489b890c82d08e98a30b0bbc076.zip | |
fix race condition when loading volumes concurrently
Diffstat (limited to 'weed/storage/disk_location.go')
| -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..73d9d8111 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -99,10 +99,9 @@ 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 } @@ -110,11 +109,14 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne // load the volume v, e := NewVolume(l.Directory, l.IdxDirectory, collection, vid, needleMapKind, nil, nil, 0, 0) if e != nil { + l.volumesLock.Unlock() glog.V(0).Infof("new volume %s error %s", volumeName, e) return false } - l.SetVolume(vid, v) + l.volumes[vid] = v + v.location = l + l.volumesLock.Unlock() size, _, _ := v.FileStat() glog.V(0).Infof("data file %s, replicaPlacement=%s v=%d size=%d ttl=%s", |
