|
@ -183,34 +183,34 @@ type Node struct { |
|
|
rack string |
|
|
rack string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type CapacityFunc func(*master_pb.DataNodeInfo) int |
|
|
|
|
|
|
|
|
type CapacityFunc func(*master_pb.DataNodeInfo) float64 |
|
|
|
|
|
|
|
|
func capacityByMaxVolumeCount(diskType types.DiskType) CapacityFunc { |
|
|
func capacityByMaxVolumeCount(diskType types.DiskType) CapacityFunc { |
|
|
return func(info *master_pb.DataNodeInfo) int { |
|
|
|
|
|
|
|
|
return func(info *master_pb.DataNodeInfo) float64 { |
|
|
diskInfo, found := info.DiskInfos[string(diskType)] |
|
|
diskInfo, found := info.DiskInfos[string(diskType)] |
|
|
if !found { |
|
|
if !found { |
|
|
return 0 |
|
|
return 0 |
|
|
} |
|
|
} |
|
|
return int(diskInfo.MaxVolumeCount) |
|
|
|
|
|
|
|
|
return float64(diskInfo.MaxVolumeCount) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func capacityByFreeVolumeCount(diskType types.DiskType) CapacityFunc { |
|
|
func capacityByFreeVolumeCount(diskType types.DiskType) CapacityFunc { |
|
|
return func(info *master_pb.DataNodeInfo) int { |
|
|
|
|
|
|
|
|
return func(info *master_pb.DataNodeInfo) float64 { |
|
|
diskInfo, found := info.DiskInfos[string(diskType)] |
|
|
diskInfo, found := info.DiskInfos[string(diskType)] |
|
|
if !found { |
|
|
if !found { |
|
|
return 0 |
|
|
return 0 |
|
|
} |
|
|
} |
|
|
return int(diskInfo.MaxVolumeCount - diskInfo.VolumeCount) |
|
|
|
|
|
|
|
|
return float64(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 float64(len(n.selectedVolumes)) / capacityFunc(n.info) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (n *Node) localVolumeNextRatio(capacityFunc CapacityFunc) float64 { |
|
|
func (n *Node) localVolumeNextRatio(capacityFunc CapacityFunc) float64 { |
|
|
return divide(len(n.selectedVolumes)+1, capacityFunc(n.info)) |
|
|
|
|
|
|
|
|
return float64(len(n.selectedVolumes)+1) / capacityFunc(n.info) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (n *Node) isOneVolumeOnly() bool { |
|
|
func (n *Node) isOneVolumeOnly() bool { |
|
@ -243,7 +243,7 @@ func sortWritableVolumes(volumes []*master_pb.VolumeInformationMessage) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func balanceSelectedVolume(commandEnv *CommandEnv, diskType types.DiskType, volumeReplicas map[uint32][]*VolumeReplica, nodes []*Node, capacityFunc CapacityFunc, sortCandidatesFn func(volumes []*master_pb.VolumeInformationMessage), applyBalancing bool) (err error) { |
|
|
func balanceSelectedVolume(commandEnv *CommandEnv, diskType types.DiskType, volumeReplicas map[uint32][]*VolumeReplica, nodes []*Node, capacityFunc CapacityFunc, sortCandidatesFn func(volumes []*master_pb.VolumeInformationMessage), applyBalancing bool) (err error) { |
|
|
selectedVolumeCount, volumeMaxCount := 0, 0 |
|
|
|
|
|
|
|
|
selectedVolumeCount, volumeMaxCount := 0, float64(0) |
|
|
var nodesWithCapacity []*Node |
|
|
var nodesWithCapacity []*Node |
|
|
for _, dn := range nodes { |
|
|
for _, dn := range nodes { |
|
|
selectedVolumeCount += len(dn.selectedVolumes) |
|
|
selectedVolumeCount += len(dn.selectedVolumes) |
|
@ -254,7 +254,7 @@ func balanceSelectedVolume(commandEnv *CommandEnv, diskType types.DiskType, volu |
|
|
volumeMaxCount += capacity |
|
|
volumeMaxCount += capacity |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
idealVolumeRatio := divide(selectedVolumeCount, volumeMaxCount) |
|
|
|
|
|
|
|
|
idealVolumeRatio := float64(selectedVolumeCount) / volumeMaxCount |
|
|
|
|
|
|
|
|
hasMoved := true |
|
|
hasMoved := true |
|
|
|
|
|
|
|
|