Skip to content

Commit c9f1ec6

Browse files
committed
mmaprototype: refactor control flow to use boolean flags
Convert return and continue statements to boolean flags (shouldReturnEarly, shouldContinue) that are checked after the block. This prepares the code for extraction into a function by moving all loop control structure outside the block that will become shedStore.
1 parent f945c0d commit c9f1ec6

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ func (cs *clusterState) rebalanceStores(
147147
rangeMoveCount := 0
148148
leaseTransferCount := 0
149149
for idx /*logging only*/, store := range sheddingStores {
150+
shouldReturnEarly := false
151+
shouldContinue := false
150152
{
151153
log.KvDistribution.Infof(ctx, "start processing shedding store s%d: cpu node load %s, store load %s, worst dim %s",
152154
store.StoreID, store.nls, store.sls, store.worstDim)
@@ -341,7 +343,8 @@ func (cs *clusterState) rebalanceStores(
341343
targetSS.maxFractionPendingIncrease, targetSS.maxFractionPendingDecrease)
342344
if leaseTransferCount >= maxLeaseTransferCount {
343345
log.KvDistribution.VInfof(ctx, 2, "reached max lease transfer count %d, returning", maxLeaseTransferCount)
344-
return changes
346+
shouldReturnEarly = true
347+
break
345348
}
346349
doneShedding = ss.maxFractionPendingDecrease >= maxFractionPendingThreshold
347350
if doneShedding {
@@ -360,7 +363,8 @@ func (cs *clusterState) rebalanceStores(
360363
// lease transfers -- so be it.
361364
log.KvDistribution.VInfof(ctx, 2, "skipping replica transfers for s%d: done shedding=%v, lease_transfers=%d",
362365
store.StoreID, doneShedding, leaseTransferCount)
363-
continue
366+
shouldContinue = true
367+
break
364368
}
365369
} else {
366370
log.KvDistribution.VInfof(ctx, 2, "skipping lease shedding: s%v != local store s%s or cpu is not overloaded: %v",
@@ -372,7 +376,8 @@ func (cs *clusterState) rebalanceStores(
372376
if store.StoreID != localStoreID && store.dimSummary[CPURate] >= overloadSlow &&
373377
now.Sub(ss.overloadStartTime) < remoteStoreLeaseSheddingGraceDuration {
374378
log.KvDistribution.VInfof(ctx, 2, "skipping remote store s%d: in lease shedding grace period", store.StoreID)
375-
continue
379+
shouldContinue = true
380+
break
376381
}
377382
// If the node is cpu overloaded, or the store/node is not fdOK, exclude
378383
// the other stores on this node from receiving replicas shed by this
@@ -550,7 +555,8 @@ func (cs *clusterState) rebalanceStores(
550555
rangeID, removeTarget.StoreID, addTarget.StoreID, changes[len(changes)-1], ss.adjusted.load, targetSS.adjusted.load)
551556
if rangeMoveCount >= maxRangeMoveCount {
552557
log.KvDistribution.VInfof(ctx, 2, "s%d has reached max range move count %d: mma returning with %d stores left in shedding stores", store.StoreID, maxRangeMoveCount, len(sheddingStores)-(idx+1))
553-
return changes
558+
shouldReturnEarly = true
559+
break
554560
}
555561
doneShedding = ss.maxFractionPendingDecrease >= maxFractionPendingThreshold
556562
if doneShedding {
@@ -566,9 +572,16 @@ func (cs *clusterState) rebalanceStores(
566572
// rebalancing to work well is not in scope.
567573
if doneShedding {
568574
log.KvDistribution.VInfof(ctx, 2, "store s%d is done shedding, moving to next store", store.StoreID)
569-
continue
575+
shouldContinue = true
576+
break
570577
}
571578
}
579+
if shouldReturnEarly {
580+
return changes
581+
}
582+
if shouldContinue {
583+
continue
584+
}
572585
}
573586
return changes
574587
}

0 commit comments

Comments
 (0)