reduce concurrent volume grow requests

This commit is contained in:
Chris Lu
2021-10-05 01:58:30 -07:00
parent 96119eab00
commit 332d49432d
3 changed files with 22 additions and 2 deletions

View File

@@ -114,6 +114,8 @@ type VolumeLayout struct {
volumeSizeLimit uint64
replicationAsMin bool
accessLock sync.RWMutex
growRequestCount int
growRequestTime time.Time
}
type VolumeLayoutStats struct {
@@ -310,6 +312,21 @@ func (vl *VolumeLayout) PickForWrite(count uint64, option *VolumeGrowOption) (*n
return &vid, count, locationList, nil
}
func (vl *VolumeLayout) HasGrowRequest() bool {
if 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++
}
func (vl *VolumeLayout) DoneGrowRequest() {
vl.growRequestTime = time.Unix(0,0)
vl.growRequestCount = 0
}
func (vl *VolumeLayout) ShouldGrowVolumes(option *VolumeGrowOption) bool {
active, crowded := vl.GetActiveVolumeCount(option)
//glog.V(0).Infof("active volume: %d, high usage volume: %d\n", active, high)