From 43101ccea03f45de6d43b41a4d08eba1de1b89e6 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 16 Feb 2021 04:27:16 -0800 Subject: [PATCH] move to the empty nodes first --- weed/shell/command_volume_balance.go | 10 ++++++++++ weed/shell/command_volume_server_evacuate.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go index f5fdf2216..a1e3c1ab6 100644 --- a/weed/shell/command_volume_balance.go +++ b/weed/shell/command_volume_balance.go @@ -213,6 +213,16 @@ func capacityByMaxVolumeCount(diskType types.DiskType) CapacityFunc { } } +func capacityByFreeVolumeCount(diskType types.DiskType) CapacityFunc { + return func(info *master_pb.DataNodeInfo) int { + diskInfo, found := info.DiskInfos[string(diskType)] + if !found { + return 0 + } + return int(diskInfo.MaxVolumeCount - diskInfo.VolumeCount) + } +} + func (n *Node) localVolumeRatio(capacityFunc CapacityFunc) float64 { return divide(len(n.selectedVolumes), capacityFunc(n.info)) } diff --git a/weed/shell/command_volume_server_evacuate.go b/weed/shell/command_volume_server_evacuate.go index 65bf578a0..8acc943cf 100644 --- a/weed/shell/command_volume_server_evacuate.go +++ b/weed/shell/command_volume_server_evacuate.go @@ -180,7 +180,7 @@ func moveAwayOneEcVolume(commandEnv *CommandEnv, ecShardInfo *master_pb.VolumeEc func moveAwayOneNormalVolume(commandEnv *CommandEnv, volumeReplicas map[uint32][]*VolumeReplica, vol *master_pb.VolumeInformationMessage, thisNode *Node, otherNodes []*Node, applyChange bool) (hasMoved bool, err error) { sort.Slice(otherNodes, func(i, j int) bool { - return otherNodes[i].localVolumeRatio(capacityByMaxVolumeCount(types.ToDiskType(vol.DiskType))) < otherNodes[j].localVolumeRatio(capacityByMaxVolumeCount(types.ToDiskType(vol.DiskType))) + return otherNodes[i].localVolumeRatio(capacityByFreeVolumeCount(types.ToDiskType(vol.DiskType))) > otherNodes[j].localVolumeRatio(capacityByFreeVolumeCount(types.ToDiskType(vol.DiskType))) }) for i := 0; i < len(otherNodes); i++ {