From e8cc3010fd559bf7270be5bd1c7232b5c7b748e1 Mon Sep 17 00:00:00 2001 From: bingoohuang Date: Wed, 23 Jan 2019 14:33:09 +0800 Subject: [PATCH] refactor code --- weed/command/server.go | 2 +- weed/storage/volume.go | 10 ---------- weed/topology/data_node.go | 6 +++--- weed/topology/volume_layout.go | 2 +- weed/topology/volume_location_list.go | 11 ++++------- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/weed/command/server.go b/weed/command/server.go index 1097ae5eb..3d8c29527 100644 --- a/weed/command/server.go +++ b/weed/command/server.go @@ -63,7 +63,7 @@ var ( masterGrpcPort = cmdServer.Flag.Int("master.port.grpc", 0, "master grpc server listen port, default to http port + 10000") masterMetaFolder = cmdServer.Flag.String("master.dir", "", "data directory to store meta data, default to same as -dir specified") masterVolumeSizeLimitMib = cmdServer.Flag.Uint("master.volumeSizeLimitMB", 30*1000, "Master stops directing writes to oversized volumes.") - masterVolumeSizeLimitArg = cmdMaster.Flag.String("master.volumeSizeLimit", "", "Master stops directing writes to oversized volumes. (eg: 30G, 20G)") + masterVolumeSizeLimitArg = cmdServer.Flag.String("master.volumeSizeLimit", "", "Master stops directing writes to oversized volumes. (eg: 30G, 20G)") masterVolumePreallocate = cmdServer.Flag.Bool("master.volumePreallocate", false, "Preallocate disk space for volumes.") masterDefaultReplicaPlacement = cmdServer.Flag.String("master.defaultReplicaPlacement", "000", "Default replication type if not specified.") diff --git a/weed/storage/volume.go b/weed/storage/volume.go index ef65a53a8..07c72ecb4 100644 --- a/weed/storage/volume.go +++ b/weed/storage/volume.go @@ -2,7 +2,6 @@ package storage import ( "fmt" - "github.com/shirou/gopsutil/disk" "os" "path" "sync" @@ -135,12 +134,3 @@ func (v *Volume) expiredLongEnough(maxDelayMinutes uint32) bool { } return false } - -func IsUnderDiskWaterLevel(path string, waterLevel uint64) (uint64, bool, error) { - stat, e := disk.Usage(path) - if e != nil { - return 0, true, e - } - - return stat.Free, stat.Free < waterLevel, nil -} diff --git a/weed/topology/data_node.go b/weed/topology/data_node.go index 467edd5da..7bb36e155 100644 --- a/weed/topology/data_node.go +++ b/weed/topology/data_node.go @@ -83,14 +83,14 @@ func (dn *DataNode) GetVolumes() (ret []storage.VolumeInfo) { return ret } -func (dn *DataNode) GetVolumesById(id storage.VolumeId) (storage.VolumeInfo, error) { +func (dn *DataNode) GetVolumesById(id storage.VolumeId) (storage.VolumeInfo, bool) { dn.RLock() defer dn.RUnlock() vInfo, ok := dn.volumes[id] if ok { - return vInfo, nil + return vInfo, true } else { - return storage.VolumeInfo{}, fmt.Errorf("volumeInfo not found") + return storage.VolumeInfo{}, false } } diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go index e423b6c92..75feb0534 100644 --- a/weed/topology/volume_layout.go +++ b/weed/topology/volume_layout.go @@ -49,7 +49,7 @@ func (vl *VolumeLayout) RegisterVolume(v *storage.VolumeInfo, dn *DataNode) { vl.vid2location[v.Id].Set(dn) // glog.V(4).Infof("volume %d added to %s len %d copy %d", v.Id, dn.Id(), vl.vid2location[v.Id].Length(), v.ReplicaPlacement.GetCopyCount()) for _, dn := range vl.vid2location[v.Id].list { - if vInfo, err := dn.GetVolumesById(v.Id); err == nil { + if vInfo, ok := dn.GetVolumesById(v.Id); ok { if vInfo.IsReadOnly() { glog.V(3).Infof("vid %d removed from writable", v.Id) return diff --git a/weed/topology/volume_location_list.go b/weed/topology/volume_location_list.go index dd8cb4a94..b93f5bbe7 100644 --- a/weed/topology/volume_location_list.go +++ b/weed/topology/volume_location_list.go @@ -76,8 +76,8 @@ func (vll *VolumeLocationList) Refresh(freshThreshHold int64) { func (vll *VolumeLocationList) Stats(vid storage.VolumeId, freshThreshHold int64) (size uint64, fileCount int) { for _, dnl := range vll.list { if dnl.LastSeen < freshThreshHold { - vinfo, err := dnl.GetVolumesById(vid) - if err == nil { + vinfo, ok := dnl.GetVolumesById(vid) + if ok { return vinfo.Size - vinfo.DeletedByteCount, vinfo.FileCount - vinfo.DeleteCount } } @@ -87,11 +87,8 @@ func (vll *VolumeLocationList) Stats(vid storage.VolumeId, freshThreshHold int64 func (vll *VolumeLocationList) HasReadOnly(id storage.VolumeId) (hasReadOnly, hasValue bool) { for _, dn := range vll.list { - vi, err := dn.GetVolumesById(id) - if err == nil { - hasValue = true - } - + var vi storage.VolumeInfo + vi, hasValue = dn.GetVolumesById(id) if vi.IsReadOnly() { hasReadOnly = true break