Skip to content

Commit b5ce551

Browse files
committed
mmaprototype: remove shouldReturnEarly flag from rebalanceState
Remove the shouldReturnEarly flag and instead check the condition directly in the loop. The loop now checks if rangeMoveCount or leaseTransferCount has reached their limits before processing each store, and breaks if either condition is met.
1 parent 1792c83 commit b5ce551

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

pkg/kv/kvserver/allocator/mmaprototype/cluster_state_rebalance_stores.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ type rebalanceState struct {
3636
rangeMoveCount int
3737
// leaseTransferCount tracks the number of lease transfers made.
3838
leaseTransferCount int
39-
// shouldReturnEarly indicates the outer loop should return immediately.
40-
shouldReturnEarly bool
4139
// shouldContinue indicates the outer loop should continue to the next iteration.
4240
shouldContinue bool
4341
// maxRangeMoveCount is the maximum number of range moves allowed.
@@ -179,7 +177,6 @@ func (cs *clusterState) rebalanceStores(
179177
changes: []PendingRangeChange{},
180178
rangeMoveCount: 0,
181179
leaseTransferCount: 0,
182-
shouldReturnEarly: false,
183180
shouldContinue: false,
184181
maxRangeMoveCount: maxRangeMoveCount,
185182
maxLeaseTransferCount: maxLeaseTransferCount,
@@ -188,10 +185,10 @@ func (cs *clusterState) rebalanceStores(
188185
rs.scratch.nodes = map[roachpb.NodeID]*NodeLoad{}
189186
rs.scratch.stores = map[roachpb.StoreID]struct{}{}
190187
for _, store := range sheddingStores {
191-
rs.rebalanceStore(store, ctx, localStoreID, now)
192-
if rs.shouldReturnEarly {
193-
return rs.changes
188+
if rs.rangeMoveCount >= rs.maxRangeMoveCount || rs.leaseTransferCount >= rs.maxLeaseTransferCount {
189+
break
194190
}
191+
rs.rebalanceStore(store, ctx, localStoreID, now)
195192
if rs.shouldContinue {
196193
rs.shouldContinue = false
197194
continue
@@ -396,7 +393,6 @@ func (rs *rebalanceState) rebalanceStore(
396393
targetSS.maxFractionPendingIncrease, targetSS.maxFractionPendingDecrease)
397394
if rs.leaseTransferCount >= rs.maxLeaseTransferCount {
398395
log.KvDistribution.VInfof(ctx, 2, "reached max lease transfer count %d, returning", rs.maxLeaseTransferCount)
399-
rs.shouldReturnEarly = true
400396
return
401397
}
402398
doneShedding = ss.maxFractionPendingDecrease >= maxFractionPendingThreshold
@@ -608,7 +604,6 @@ func (rs *rebalanceState) rebalanceStore(
608604
rangeID, removeTarget.StoreID, addTarget.StoreID, rs.changes[len(rs.changes)-1], ss.adjusted.load, targetSS.adjusted.load)
609605
if rs.rangeMoveCount >= rs.maxRangeMoveCount {
610606
log.KvDistribution.VInfof(ctx, 2, "s%d has reached max range move count %d: mma returning", store.StoreID, rs.maxRangeMoveCount)
611-
rs.shouldReturnEarly = true
612607
return
613608
}
614609
doneShedding = ss.maxFractionPendingDecrease >= maxFractionPendingThreshold

0 commit comments

Comments
 (0)