SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
avoid repeated calls to heavy-weighted viper
chrislu55976ae04a22
diff --git a/weed/server/master_server.go b/weed/server/master_server.goindex a2f3c76920..f89c9598f8 100644--- a/weed/server/master_server.go+++ b/weed/server/master_server.go@@ -97,6 +97,11 @@ func NewMasterServer(r *mux.Router, option *MasterOption, peers map[string]pb.Sev.SetDefault("master.volume_growth.copy_3", 3)v.SetDefault("master.volume_growth.copy_other", 1)v.SetDefault("master.volume_growth.threshold", 0.9)+ topology.VolumeGrowStrategy.Copy1Count = v.GetInt("master.volume_growth.copy_1")+ topology.VolumeGrowStrategy.Copy2Count = v.GetInt("master.volume_growth.copy_2")+ topology.VolumeGrowStrategy.Copy3Count = v.GetInt("master.volume_growth.copy_3")+ topology.VolumeGrowStrategy.CopyOtherCount = v.GetInt("master.volume_growth.copy_other")+ topology.VolumeGrowStrategy.Threshold = v.GetFloat64("master.volume_growth.threshold")var preallocateSize int64if option.VolumePreallocate {@@ -151,7 +156,7 @@ func NewMasterServer(r *mux.Router, option *MasterOption, peers map[string]pb.Sems.Topo.StartRefreshWritableVolumes(ms.grpcDialOption,ms.option.GarbageThreshold,- v.GetFloat64("master.volume_growth.threshold"),+ topology.VolumeGrowStrategy.Threshold,ms.preallocateSize,)diff --git a/weed/topology/volume_growth.go b/weed/topology/volume_growth.goindex cf5690cecd..9885fc2d1b 100644--- a/weed/topology/volume_growth.go+++ b/weed/topology/volume_growth.go@@ -15,7 +15,6 @@ import ("github.com/seaweedfs/seaweedfs/weed/storage/needle""github.com/seaweedfs/seaweedfs/weed/storage/super_block""github.com/seaweedfs/seaweedfs/weed/storage/types"- "github.com/seaweedfs/seaweedfs/weed/util")/*@@ -31,6 +30,24 @@ type VolumeGrowRequest struct {Count int}+type volumeGrowthStrategy struct {+ Copy1Count int+ Copy2Count int+ Copy3Count int+ CopyOtherCount int+ Threshold float64+}++var (+ VolumeGrowStrategy = volumeGrowthStrategy{+ Copy1Count: 7,+ Copy2Count: 6,+ Copy3Count: 3,+ CopyOtherCount: 1,+ Threshold: 0.9,+ }+)+type VolumeGrowOption struct {Collection string `json:"collection,omitempty"`ReplicaPlacement *super_block.ReplicaPlacement `json:"replication,omitempty"`@@ -52,11 +69,6 @@ func (o *VolumeGrowOption) String() string {return string(blob)}-func (o *VolumeGrowOption) Threshold() float64 {- v := util.GetViper()- return v.GetFloat64("master.volume_growth.threshold")-}-func NewDefaultVolumeGrowth() *VolumeGrowth {return &VolumeGrowth{}}@@ -64,16 +76,14 @@ func NewDefaultVolumeGrowth() *VolumeGrowth {// one replication type may need rp.GetCopyCount() actual volumes// given copyCount, how many logical volumes to createfunc (vg *VolumeGrowth) findVolumeCount(copyCount int) (count int) {- v := util.GetViper()switch copyCount {- case 1:- count = v.GetInt("master.volume_growth.copy_1")+ case 1: count = VolumeGrowStrategy.Copy1Countcase 2:- count = v.GetInt("master.volume_growth.copy_2")+ count = VolumeGrowStrategy.Copy2Countcase 3:- count = v.GetInt("master.volume_growth.copy_3")+ count = VolumeGrowStrategy.Copy3Countdefault:- count = v.GetInt("master.volume_growth.copy_other")+ count = VolumeGrowStrategy.CopyOtherCount}return}diff --git a/weed/topology/volume_growth_test.go b/weed/topology/volume_growth_test.goindex 04c5e8aeb2..1624ec32a8 100644--- a/weed/topology/volume_growth_test.go+++ b/weed/topology/volume_growth_test.go@@ -4,7 +4,6 @@ import ("encoding/json""fmt""github.com/seaweedfs/seaweedfs/weed/storage/types"- "github.com/seaweedfs/seaweedfs/weed/util""testing""github.com/seaweedfs/seaweedfs/weed/sequence"@@ -420,8 +419,7 @@ func TestPickForWrite(t *testing.T) {Rack: "",DataNode: "",}- v := util.GetViper()- v.Set("master.volume_growth.threshold", 0.9)+ VolumeGrowStrategy.Threshold = 0.9for _, rpStr := range []string{"001", "010", "100"} {rp, _ := super_block.NewReplicaPlacementFromString(rpStr)vl := topo.GetVolumeLayout("test", rp, needle.EMPTY_TTL, types.HardDriveType)diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.goindex 2296a0f92b..4467b2dc87 100644--- a/weed/topology/volume_layout.go+++ b/weed/topology/volume_layout.go@@ -303,7 +303,7 @@ func (vl *VolumeLayout) PickForWrite(count uint64, option *VolumeGrowOption) (vi// check whether picked file is close to fulldn := locationList.Head()info, _ := dn.GetVolumesById(vid)- if float64(info.Size) > float64(vl.volumeSizeLimit)*option.Threshold() {+ if float64(info.Size) > float64(vl.volumeSizeLimit)*VolumeGrowStrategy.Threshold {shouldGrow = true}return vid, count, locationList.Copy(), shouldGrow, nil@@ -334,7 +334,7 @@ func (vl *VolumeLayout) PickForWrite(count uint64, option *VolumeGrowOption) (vivid, locationList = writableVolumeId, volumeLocationList.Copy()// check whether picked file is close to fullinfo, _ := dn.GetVolumesById(writableVolumeId)- if float64(info.Size) > float64(vl.volumeSizeLimit)*option.Threshold() {+ if float64(info.Size) > float64(vl.volumeSizeLimit)*VolumeGrowStrategy.Threshold {shouldGrow = true}counter = count@@ -370,7 +370,6 @@ func (vl *VolumeLayout) GetActiveVolumeCount(option *VolumeGrowOption) (total, areturn len(vl.writables), len(vl.writables), len(vl.crowded)}total = len(vl.writables)- threshold := option.Threshold()for _, v := range vl.writables {for _, dn := range vl.vid2location[v].list {if dn.GetDataCenter().Id() == NodeId(option.DataCenter) {@@ -382,7 +381,7 @@ func (vl *VolumeLayout) GetActiveVolumeCount(option *VolumeGrowOption) (total, a}active++info, _ := dn.GetVolumesById(v)- if float64(info.Size) > float64(vl.volumeSizeLimit)*threshold {+ if float64(info.Size) > float64(vl.volumeSizeLimit)* VolumeGrowStrategy.Threshold{crowded++}}