Skip to content

Commit 51e53ae

Browse files
committed
mmaprototype: wrap lease rebalancing logic in inline function
Wrap the lease rebalancing logic in an inline function that takes all necessary parameters and returns whether to skip replica moves. This prepares the code for extraction to a separate method. The function converts early returns to return statements with the skip flag, making the control flow explicit and ready for method extraction.
1 parent 34a439f commit 51e53ae

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (rs *rebalanceState) rebalanceStore(
227227
// behalf of a particular store (vs. being called on behalf of the set
228228
// of local store IDs)?
229229
if ss.StoreID == localStoreID && store.dimSummary[CPURate] >= overloadSlow {
230-
{
230+
shouldSkipReplicaMoves := func(rs *rebalanceState, ss *storeState, store sheddingStore, ctx context.Context, localStoreID roachpb.StoreID, now time.Time) bool {
231231
log.KvDistribution.VInfof(ctx, 2, "local store s%d is CPU overloaded (%v >= %v), attempting lease transfers first",
232232
store.StoreID, store.dimSummary[CPURate], overloadSlow)
233233
// This store is local, and cpu overloaded. Shed leases first.
@@ -237,6 +237,7 @@ func (rs *rebalanceState) rebalanceStore(
237237
localLeaseTransferCount := 0
238238
topKRanges := ss.adjusted.topKRanges[localStoreID]
239239
n := topKRanges.len()
240+
doneShedding := false
240241
for i := 0; i < n; i++ {
241242
rangeID := topKRanges.index(i)
242243
rstate := rs.cs.ranges[rangeID]
@@ -389,7 +390,7 @@ func (rs *rebalanceState) rebalanceStore(
389390
targetSS.maxFractionPendingIncrease, targetSS.maxFractionPendingDecrease)
390391
if rs.leaseTransferCount >= rs.maxLeaseTransferCount {
391392
log.KvDistribution.VInfof(ctx, 2, "reached max lease transfer count %d, returning", rs.maxLeaseTransferCount)
392-
return
393+
break
393394
}
394395
doneShedding = ss.maxFractionPendingDecrease >= maxFractionPendingThreshold
395396
if doneShedding {
@@ -408,8 +409,12 @@ func (rs *rebalanceState) rebalanceStore(
408409
// lease transfers -- so be it.
409410
log.KvDistribution.VInfof(ctx, 2, "skipping replica transfers for s%d: done shedding=%v, lease_transfers=%d",
410411
store.StoreID, doneShedding, localLeaseTransferCount)
411-
return
412+
return true
412413
}
414+
return false
415+
}(rs, ss, store, ctx, localStoreID, now)
416+
if shouldSkipReplicaMoves {
417+
return
413418
}
414419
} else {
415420
log.KvDistribution.VInfof(ctx, 2, "skipping lease shedding: s%v != local store s%s or cpu is not overloaded: %v",

0 commit comments

Comments
 (0)