mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-01-18 22:43:41 +08:00
fix divide by zero
This commit is contained in:
parent
f9131de43f
commit
0d74ac9224
@ -56,7 +56,7 @@ func pickBrokers(brokers cmap.ConcurrentMap[string, *BrokerStats], count int32)
|
||||
return pickedBrokers
|
||||
}
|
||||
|
||||
func EnsureAssignmentsToActiveBrokers(activeBrokers cmap.ConcurrentMap[string,*BrokerStats], assignments []*mq_pb.BrokerPartitionAssignment) (addedAssignments, updatedAssignments []*mq_pb.BrokerPartitionAssignment) {
|
||||
func EnsureAssignmentsToActiveBrokers(activeBrokers cmap.ConcurrentMap[string, *BrokerStats], assignments []*mq_pb.BrokerPartitionAssignment) (addedAssignments, updatedAssignments []*mq_pb.BrokerPartitionAssignment) {
|
||||
for _, assignment := range assignments {
|
||||
if assignment.LeaderBroker == "" {
|
||||
addedAssignments = append(addedAssignments, assignment)
|
||||
@ -69,13 +69,17 @@ func EnsureAssignmentsToActiveBrokers(activeBrokers cmap.ConcurrentMap[string,*B
|
||||
}
|
||||
|
||||
// pick the brokers with the least number of partitions
|
||||
pickedBrokers := pickBrokers(activeBrokers, int32(len(addedAssignments)))
|
||||
for i, assignment := range addedAssignments {
|
||||
assignment.LeaderBroker = pickedBrokers[i]
|
||||
if len(addedAssignments) > 0 {
|
||||
pickedBrokers := pickBrokers(activeBrokers, int32(len(addedAssignments)))
|
||||
for i, assignment := range addedAssignments {
|
||||
assignment.LeaderBroker = pickedBrokers[i]
|
||||
}
|
||||
}
|
||||
pickedBrokers = pickBrokers(activeBrokers, int32(len(updatedAssignments)))
|
||||
for i, assignment := range updatedAssignments {
|
||||
assignment.LeaderBroker = pickedBrokers[i]
|
||||
if len(updatedAssignments) == 0 {
|
||||
pickedBrokers := pickBrokers(activeBrokers, int32(len(updatedAssignments)))
|
||||
for i, assignment := range updatedAssignments {
|
||||
assignment.LeaderBroker = pickedBrokers[i]
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user