Browse Source

refactor code

pull/843/head
bingoohuang 7 years ago
parent
commit
e8cc3010fd
  1. 2
      weed/command/server.go
  2. 10
      weed/storage/volume.go
  3. 6
      weed/topology/data_node.go
  4. 2
      weed/topology/volume_layout.go
  5. 11
      weed/topology/volume_location_list.go

2
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.")

10
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
}

6
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
}
}

2
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

11
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

Loading…
Cancel
Save