diff options
| author | Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> | 2022-08-30 01:23:02 +0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-29 13:23:02 -0700 |
| commit | 4966a3abc75524a28a91359b65ab3b9ca3e2bdf4 (patch) | |
| tree | dafe6e0cad8bdfda4d2c0c9ef58db5f08fcb31c4 | |
| parent | 42b72e400684f16409129d19f2e770654e4fccc1 (diff) | |
| download | seaweedfs-4966a3abc75524a28a91359b65ab3b9ca3e2bdf4.tar.xz seaweedfs-4966a3abc75524a28a91359b65ab3b9ca3e2bdf4.zip | |
avoid race conditions access to growRequestCount (#3537)
https://github.com/seaweedfs/seaweedfs/issues/3511
| -rw-r--r-- | weed/topology/volume_layout.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go index 8d28eff13..760cecbdd 100644 --- a/weed/topology/volume_layout.go +++ b/weed/topology/volume_layout.go @@ -6,6 +6,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/storage/types" "math/rand" "sync" + "sync/atomic" "time" "github.com/seaweedfs/seaweedfs/weed/glog" @@ -114,7 +115,7 @@ type VolumeLayout struct { volumeSizeLimit uint64 replicationAsMin bool accessLock sync.RWMutex - growRequestCount int + growRequestCount int32 growRequestTime time.Time } @@ -319,18 +320,19 @@ func (vl *VolumeLayout) PickForWrite(count uint64, option *VolumeGrowOption) (*n } func (vl *VolumeLayout) HasGrowRequest() bool { - if vl.growRequestCount > 0 && vl.growRequestTime.Add(time.Minute).After(time.Now()) { + if atomic.LoadInt32(&vl.growRequestCount) > 0 && + vl.growRequestTime.Add(time.Minute).After(time.Now()) { return true } return false } func (vl *VolumeLayout) AddGrowRequest() { vl.growRequestTime = time.Now() - vl.growRequestCount++ + atomic.AddInt32(&vl.growRequestCount, 1) } func (vl *VolumeLayout) DoneGrowRequest() { vl.growRequestTime = time.Unix(0, 0) - vl.growRequestCount = 0 + atomic.StoreInt32(&vl.growRequestCount, 0) } func (vl *VolumeLayout) ShouldGrowVolumes(option *VolumeGrowOption) bool { |
