mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-11-09 10:55:16 +08:00
move to the empty nodes first
This commit is contained in:
@@ -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 {
|
func (n *Node) localVolumeRatio(capacityFunc CapacityFunc) float64 {
|
||||||
return divide(len(n.selectedVolumes), capacityFunc(n.info))
|
return divide(len(n.selectedVolumes), capacityFunc(n.info))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
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 {
|
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++ {
|
for i := 0; i < len(otherNodes); i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user