aboutsummaryrefslogtreecommitdiff
path: root/weed/topology/volume_layout.go
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2024-07-31 01:21:35 +0500
committerGitHub <noreply@github.com>2024-07-30 13:21:35 -0700
commitb2ffcdaab2e662d85913eee7fa11eddb57d3052e (patch)
tree372561ac009a61554c070da31dae7de096a00fcc /weed/topology/volume_layout.go
parent69bcdf470bf62e9ba71da283d60a203bdbcb3fcb (diff)
downloadseaweedfs-b2ffcdaab2e662d85913eee7fa11eddb57d3052e.tar.xz
seaweedfs-b2ffcdaab2e662d85913eee7fa11eddb57d3052e.zip
[master] do sync grow request only if absolutely necessary (#5821)
* do sync grow request only if absolutely necessary https://github.com/seaweedfs/seaweedfs/pull/5819 * remove check VolumeGrowStrategy Threshold on PickForWrite * fix fmt.Errorf
Diffstat (limited to 'weed/topology/volume_layout.go')
-rw-r--r--weed/topology/volume_layout.go36
1 files changed, 11 insertions, 25 deletions
diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go
index a1af553fd..e2a360165 100644
--- a/weed/topology/volume_layout.go
+++ b/weed/topology/volume_layout.go
@@ -1,7 +1,6 @@
package topology
import (
- "errors"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/stats"
"math/rand"
@@ -28,9 +27,10 @@ const (
type volumeState string
const (
- readOnlyState volumeState = "ReadOnly"
- oversizedState = "Oversized"
- crowdedState = "Crowded"
+ readOnlyState volumeState = "ReadOnly"
+ oversizedState = "Oversized"
+ crowdedState = "Crowded"
+ noWritableVolumes = "No writable volumes"
)
type stateIndicator func(copyState) bool
@@ -108,7 +108,7 @@ func (v *volumesBinaryState) copyState(list *VolumeLocationList) copyState {
type VolumeLayout struct {
growRequest atomic.Bool
lastGrowCount atomic.Uint32
- rp *super_block.ReplicaPlacement
+ rp *super_block.ReplicaPlacement
ttl *needle.TTL
diskType types.DiskType
vid2location map[needle.VolumeId]*VolumeLocationList
@@ -293,23 +293,15 @@ func (vl *VolumeLayout) PickForWrite(count uint64, option *VolumeGrowOption) (vi
lenWriters := len(vl.writables)
if lenWriters <= 0 {
- //glog.V(0).Infoln("No more writable volumes!")
- shouldGrow = true
- return 0, 0, nil, shouldGrow, errors.New("No more writable volumes!")
+ return 0, 0, nil, true, fmt.Errorf("%s in volume layout", noWritableVolumes)
}
if option.DataCenter == "" && option.Rack == "" && option.DataNode == "" {
vid := vl.writables[rand.Intn(lenWriters)]
locationList = vl.vid2location[vid]
- if locationList != nil && locationList.Length() > 0 {
- // check whether picked file is close to full
- dn := locationList.Head()
- info, _ := dn.GetVolumesById(vid)
- if float64(info.Size) > float64(vl.volumeSizeLimit)*VolumeGrowStrategy.Threshold {
- shouldGrow = true
- }
- return vid, count, locationList.Copy(), shouldGrow, nil
+ if locationList == nil || len(locationList.list) == 0 {
+ return 0, 0, nil, false, fmt.Errorf("Strangely vid %s is on no machine!", vid.String())
}
- return 0, 0, nil, shouldGrow, errors.New("Strangely vid " + vid.String() + " is on no machine!")
+ return vid, count, locationList.Copy(), false, nil
}
// clone vl.writables
@@ -332,17 +324,11 @@ func (vl *VolumeLayout) PickForWrite(count uint64, option *VolumeGrowOption) (vi
if option.DataNode != "" && dn.Id() != NodeId(option.DataNode) {
continue
}
- vid, locationList = writableVolumeId, volumeLocationList.Copy()
- // check whether picked file is close to full
- info, _ := dn.GetVolumesById(writableVolumeId)
- if float64(info.Size) > float64(vl.volumeSizeLimit)*VolumeGrowStrategy.Threshold {
- shouldGrow = true
- }
- counter = count
+ vid, locationList, counter = writableVolumeId, volumeLocationList.Copy(), count
return
}
}
- return vid, count, locationList, true, fmt.Errorf("No writable volumes in DataCenter:%v Rack:%v DataNode:%v", option.DataCenter, option.Rack, option.DataNode)
+ return vid, count, locationList, true, fmt.Errorf("%s in DataCenter:%v Rack:%v DataNode:%v", noWritableVolumes, option.DataCenter, option.Rack, option.DataNode)
}
func (vl *VolumeLayout) HasGrowRequest() bool {