MCPcopy
hub / github.com/IBM/sarama / leastUsedBroker

Function leastUsedBroker

examples/alter_partition_reassignments/main.go:177–190  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
177func 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.

Callers 1

buildTargetAssignmentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected