avoid race conditions access to growRequestCount (#3537)
https://github.com/seaweedfs/seaweedfs/issues/3511
This commit is contained in:
committed by
GitHub
parent
42b72e4006
commit
4966a3abc7
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
@@ -114,7 +115,7 @@ type VolumeLayout struct {
|
|||||||
volumeSizeLimit uint64
|
volumeSizeLimit uint64
|
||||||
replicationAsMin bool
|
replicationAsMin bool
|
||||||
accessLock sync.RWMutex
|
accessLock sync.RWMutex
|
||||||
growRequestCount int
|
growRequestCount int32
|
||||||
growRequestTime time.Time
|
growRequestTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,18 +320,19 @@ func (vl *VolumeLayout) PickForWrite(count uint64, option *VolumeGrowOption) (*n
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (vl *VolumeLayout) HasGrowRequest() bool {
|
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 true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func (vl *VolumeLayout) AddGrowRequest() {
|
func (vl *VolumeLayout) AddGrowRequest() {
|
||||||
vl.growRequestTime = time.Now()
|
vl.growRequestTime = time.Now()
|
||||||
vl.growRequestCount++
|
atomic.AddInt32(&vl.growRequestCount, 1)
|
||||||
}
|
}
|
||||||
func (vl *VolumeLayout) DoneGrowRequest() {
|
func (vl *VolumeLayout) DoneGrowRequest() {
|
||||||
vl.growRequestTime = time.Unix(0, 0)
|
vl.growRequestTime = time.Unix(0, 0)
|
||||||
vl.growRequestCount = 0
|
atomic.StoreInt32(&vl.growRequestCount, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vl *VolumeLayout) ShouldGrowVolumes(option *VolumeGrowOption) bool {
|
func (vl *VolumeLayout) ShouldGrowVolumes(option *VolumeGrowOption) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user