Skip to content

Commit

Permalink
avoid race conditions access to SuperBlock.Version (seaweedfs#3539)
Browse files Browse the repository at this point in the history
* avoid race conditions access to  SuperBlock.Version
seaweedfs#3515

* superBlockAccessLock replace to sync.Mutex
  • Loading branch information
kmlebedev authored Aug 30, 2022
1 parent ae6292f commit ade94b0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions weed/storage/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Volume struct {
super_block.SuperBlock

dataFileAccessLock sync.RWMutex
superBlockAccessLock sync.Mutex
asyncRequestsChan chan *needle.AsyncRequest
lastModifiedTsSeconds uint64 // unix time in seconds
lastAppendAtNs uint64 // unix time in nanoseconds
Expand Down Expand Up @@ -97,6 +98,8 @@ func (v *Volume) FileName(ext string) (fileName string) {
}

func (v *Volume) Version() needle.Version {
v.superBlockAccessLock.Lock()
defer v.superBlockAccessLock.Unlock()
if v.volumeInfo.Version != 0 {
v.SuperBlock.Version = needle.Version(v.volumeInfo.Version)
}
Expand Down

0 comments on commit ade94b0

Please sign in to comment.