From ade94b0d0a71db7db117454c075dc93f839e1c9c Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Tue, 30 Aug 2022 12:08:00 +0500 Subject: [PATCH] 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 --- weed/storage/volume.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/weed/storage/volume.go b/weed/storage/volume.go index 91d2d0d1f..e48a2f49a 100644 --- a/weed/storage/volume.go +++ b/weed/storage/volume.go @@ -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 @@ -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) }