Skip to content

Commit 34a439f

Browse files
committed
mmaprototype: add local lease transfer counter and fix bug
Add a local counter to track lease transfers made during processing of a single store, and use it to fix the bug where the global counter was incorrectly used to determine if this store transferred leases. The local counter is incremented alongside the global counter, which is still needed for loop termination across all stores. The check at the end of lease rebalancing now correctly uses the local counter to decide whether to skip replica transfers for this specific store.
1 parent 01d86f3 commit 34a439f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ func (rs *rebalanceState) rebalanceStore(
234234
//
235235
// NB: any ranges at this store that don't have pending changes must
236236
// have this local store as the leaseholder.
237+
localLeaseTransferCount := 0
237238
topKRanges := ss.adjusted.topKRanges[localStoreID]
238239
n := topKRanges.len()
239240
for i := 0; i < n; i++ {
@@ -375,6 +376,7 @@ func (rs *rebalanceState) rebalanceStore(
375376
rs.cs.addPendingRangeChange(leaseChange)
376377
rs.changes = append(rs.changes, leaseChange)
377378
rs.leaseTransferCount++
379+
localLeaseTransferCount++
378380
if rs.changes[len(rs.changes)-1].IsChangeReplicas() || !rs.changes[len(rs.changes)-1].IsTransferLease() {
379381
panic(fmt.Sprintf("lease transfer is invalid: %v", rs.changes[len(rs.changes)-1]))
380382
}
@@ -396,7 +398,7 @@ func (rs *rebalanceState) rebalanceStore(
396398
break
397399
}
398400
}
399-
if doneShedding || rs.leaseTransferCount > 0 {
401+
if doneShedding || localLeaseTransferCount > 0 {
400402
// If managed to transfer a lease, wait for it to be done, before
401403
// shedding replicas from this store (which is more costly). Otherwise
402404
// we may needlessly start moving replicas. Note that the store
@@ -405,7 +407,7 @@ func (rs *rebalanceState) rebalanceStore(
405407
// pending from a load perspective, so we *may* not be able to do more
406408
// lease transfers -- so be it.
407409
log.KvDistribution.VInfof(ctx, 2, "skipping replica transfers for s%d: done shedding=%v, lease_transfers=%d",
408-
store.StoreID, doneShedding, rs.leaseTransferCount)
410+
store.StoreID, doneShedding, localLeaseTransferCount)
409411
return
410412
}
411413
}

0 commit comments

Comments
 (0)