leastUsedBroker returns the broker in brokerIDs (sorted ascending) that is not already in exclude and currently hosts the fewest replicas, breaking ties by lower broker ID. ok is false if every broker is excluded.
(brokerIDs, exclude []int32, usage map[int32]int)
| 175 | // not already in exclude and currently hosts the fewest replicas, breaking |
| 176 | // ties by lower broker ID. ok is false if every broker is excluded. |
| 177 | func leastUsedBroker(brokerIDs, exclude []int32, usage map[int32]int) (int32, bool) { |
| 178 | var best int32 |
| 179 | bestUsage := -1 |
| 180 | for _, id := range brokerIDs { |
| 181 | if slices.Contains(exclude, id) { |
| 182 | continue |
| 183 | } |
| 184 | if bestUsage == -1 || usage[id] < bestUsage { |
| 185 | best = id |
| 186 | bestUsage = usage[id] |
| 187 | } |
| 188 | } |
| 189 | return best, bestUsage != -1 |
| 190 | } |
| 191 | |
| 192 | // waitForReassignment polls ListPartitionReassignments until the broker stops |
| 193 | // reporting any in-progress reassignment for the topic, or the timeout fires. |
no outgoing calls
no test coverage detected