avoid race conditions access to SuperBlock.Version (#3539)

* avoid race conditions access to  SuperBlock.Version
https://github.com/seaweedfs/seaweedfs/issues/3515

* superBlockAccessLock replace to sync.Mutex
This commit is contained in:
Konstantin Lebedev 2022-08-30 12:08:00 +05:00 committed by GitHub
parent ae6292f9f0
commit ade94b0d0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -36,6 +36,7 @@ type Volume struct {
super_block.SuperBlock super_block.SuperBlock
dataFileAccessLock sync.RWMutex dataFileAccessLock sync.RWMutex
superBlockAccessLock sync.Mutex
asyncRequestsChan chan *needle.AsyncRequest asyncRequestsChan chan *needle.AsyncRequest
lastModifiedTsSeconds uint64 // unix time in seconds lastModifiedTsSeconds uint64 // unix time in seconds
lastAppendAtNs uint64 // unix time in nanoseconds lastAppendAtNs uint64 // unix time in nanoseconds
@ -97,6 +98,8 @@ func (v *Volume) FileName(ext string) (fileName string) {
} }
func (v *Volume) Version() needle.Version { func (v *Volume) Version() needle.Version {
v.superBlockAccessLock.Lock()
defer v.superBlockAccessLock.Unlock()
if v.volumeInfo.Version != 0 { if v.volumeInfo.Version != 0 {
v.SuperBlock.Version = needle.Version(v.volumeInfo.Version) v.SuperBlock.Version = needle.Version(v.volumeInfo.Version)
} }