buildTargetAssignment grows each partition's replica list to targetRF by appending the least-used broker IDs not already in the partition's list. Existing replicas are preserved in order so the preferred leader does not move. Partitions that are already at or above the target RF are passed through u
(current [][]int32, brokerIDs []int32, targetRF int)
| 147 | // move. Partitions that are already at or above the target RF are passed |
| 148 | // through unchanged. |
| 149 | func buildTargetAssignment(current [][]int32, brokerIDs []int32, targetRF int) ([][]int32, bool) { |
| 150 | usage := make(map[int32]int, len(brokerIDs)) |
| 151 | for _, replicas := range current { |
| 152 | for _, id := range replicas { |
| 153 | usage[id]++ |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | target := make([][]int32, len(current)) |
| 158 | changed := false |
| 159 | for i, replicas := range current { |
| 160 | target[i] = slices.Clone(replicas) |
| 161 | for len(target[i]) < targetRF { |
| 162 | id, ok := leastUsedBroker(brokerIDs, target[i], usage) |
| 163 | if !ok { |
| 164 | break |
| 165 | } |
| 166 | target[i] = append(target[i], id) |
| 167 | usage[id]++ |
| 168 | changed = true |
| 169 | } |
| 170 | } |
| 171 | return target, changed |
| 172 | } |
| 173 | |
| 174 | // leastUsedBroker returns the broker in brokerIDs (sorted ascending) that is |
| 175 | // not already in exclude and currently hosts the fewest replicas, breaking |
no test coverage detected