From 4d1484628adbb73dfaf619c3fbe21521b54c4619 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 3 Jul 2020 16:41:30 -0700 Subject: [PATCH] refactoring --- weed/command/volume.go | 14 +++++++------- weed/server/volume_server.go | 4 ++-- weed/storage/store.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/weed/command/volume.go b/weed/command/volume.go index c7eac95b6..1b222f090 100644 --- a/weed/command/volume.go +++ b/weed/command/volume.go @@ -52,7 +52,7 @@ type VolumeServerOptions struct { memProfile *string compactionMBPerSecond *int fileSizeLimitMB *int - minFreeSpacePercent []float32 + minFreeSpacePercents []float32 pprof *bool // pulseSeconds *int } @@ -137,18 +137,18 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v minFreeSpacePercentStrings := strings.Split(minFreeSpacePercent, ",") for _, freeString := range minFreeSpacePercentStrings { if value, e := strconv.ParseFloat(freeString, 32); e == nil { - v.minFreeSpacePercent = append(v.minFreeSpacePercent, float32(value)) + v.minFreeSpacePercents = append(v.minFreeSpacePercents, float32(value)) } else { glog.Fatalf("The value specified in -minFreeSpacePercent not a valid value %s", freeString) } } - if len(v.minFreeSpacePercent) == 1 && len(v.folders) > 1 { + if len(v.minFreeSpacePercents) == 1 && len(v.folders) > 1 { for i := 0; i < len(v.folders)-1; i++ { - v.minFreeSpacePercent = append(v.minFreeSpacePercent, v.minFreeSpacePercent[0]) + v.minFreeSpacePercents = append(v.minFreeSpacePercents, v.minFreeSpacePercents[0]) } } - if len(v.folders) != len(v.minFreeSpacePercent) { - glog.Fatalf("%d directories by -dir, but only %d minFreeSpacePercent is set by -minFreeSpacePercent", len(v.folders), len(v.minFreeSpacePercent)) + if len(v.folders) != len(v.minFreeSpacePercents) { + glog.Fatalf("%d directories by -dir, but only %d minFreeSpacePercent is set by -minFreeSpacePercent", len(v.folders), len(v.minFreeSpacePercents)) } // security related white list configuration @@ -196,7 +196,7 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v volumeServer := weed_server.NewVolumeServer(volumeMux, publicVolumeMux, *v.ip, *v.port, *v.publicUrl, - v.folders, v.folderMaxLimits, v.minFreeSpacePercent, + v.folders, v.folderMaxLimits, v.minFreeSpacePercents, volumeNeedleMapKind, strings.Split(masters, ","), 5, *v.dataCenter, *v.rack, v.whiteList, diff --git a/weed/server/volume_server.go b/weed/server/volume_server.go index 367e39d8a..b7ed81be0 100644 --- a/weed/server/volume_server.go +++ b/weed/server/volume_server.go @@ -34,7 +34,7 @@ type VolumeServer struct { func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string, port int, publicUrl string, - folders []string, maxCounts []int, minFreeSpacePercent []float32, + folders []string, maxCounts []int, minFreeSpacePercents []float32, needleMapKind storage.NeedleMapType, masterNodes []string, pulseSeconds int, dataCenter string, rack string, @@ -65,7 +65,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string, fileSizeLimitBytes: int64(fileSizeLimitMB) * 1024 * 1024, } vs.SeedMasterNodes = masterNodes - vs.store = storage.NewStore(vs.grpcDialOption, port, ip, publicUrl, folders, maxCounts, minFreeSpacePercent, vs.needleMapKind) + vs.store = storage.NewStore(vs.grpcDialOption, port, ip, publicUrl, folders, maxCounts, minFreeSpacePercents, vs.needleMapKind) vs.guard = security.NewGuard(whiteList, signingKey, expiresAfterSec, readSigningKey, readExpiresAfterSec) handleStaticResources(adminMux) diff --git a/weed/storage/store.go b/weed/storage/store.go index 2aff8c93f..0ac3381c5 100644 --- a/weed/storage/store.go +++ b/weed/storage/store.go @@ -48,11 +48,11 @@ func (s *Store) String() (str string) { return } -func NewStore(grpcDialOption grpc.DialOption, port int, ip, publicUrl string, dirnames []string, maxVolumeCounts []int, freeDiskSpaceWatermark []float32, needleMapKind NeedleMapType) (s *Store) { +func NewStore(grpcDialOption grpc.DialOption, port int, ip, publicUrl string, dirnames []string, maxVolumeCounts []int, minFreeSpacePercents []float32, needleMapKind NeedleMapType) (s *Store) { s = &Store{grpcDialOption: grpcDialOption, Port: port, Ip: ip, PublicUrl: publicUrl, NeedleMapType: needleMapKind} s.Locations = make([]*DiskLocation, 0) for i := 0; i < len(dirnames); i++ { - location := NewDiskLocation(dirnames[i], maxVolumeCounts[i], freeDiskSpaceWatermark[i]) + location := NewDiskLocation(dirnames[i], maxVolumeCounts[i], minFreeSpacePercents[i]) location.loadExistingVolumes(needleMapKind) s.Locations = append(s.Locations, location) stats.VolumeServerMaxVolumeCounter.Add(float64(maxVolumeCounts[i]))