Skip to content

Commit 4c8e2ec

Browse files
craig[bot]tbg
andcommitted
157761: mmaprototype: extract `rebalance{Leases,Replicas}` from `rebalanceStore` r=tbg a=tbg **Leases:** This PR refactors `rebalanceStore` by extracting the lease rebalancing logic into a standalone `rebalanceLeases` method on `rebalanceState`. The method encapsulates the logic for handling lease transfers when a local store is CPU overloaded, improving code organization and reducing the complexity of `rebalanceStore`. As part of this refactor, we also fix a bug where the global `leaseTransferCount` was incorrectly used to determine if the current store transferred leases. The fix introduces a local counter that tracks lease transfers made during processing of a single store. It feels a bit sad to fix a bug without adding a test, but this felt too good to pass up, and the refactors are precursors to plenty of testing in the context of adding a notion of replica disposition. The refactoring was done incrementally in small, reviewable commits: 1. Indent the block with explicit braces (mechanical whitespace change) 2. Add local counter and fix the bug 3. Wrap the logic in an inline function 4. Extract to method (done mechanically by the author using IDE tooling) There should be zero behavior changes in this work (aside from the bug fix). **Replicas:** This PR refactors `rebalanceStore` by extracting the replica rebalancing logic into a standalone `rebalanceReplicas` method on `rebalanceState`. This separation improves code organization by isolating the replica movement logic from the lease rebalancing logic, making the codebase easier to understand and maintain. The refactoring was done incrementally in small, reviewable commits: 1. Added a code block wrapper around the replica rebalancing logic 2. Moved the `doneShedding` variable declaration into the block 3. Added method scaffolding with an IIF wrapper to set up the call site 4. Extracted the code into the `rebalanceReplicas` method (done manually using IDE tooling) There should be zero behavior changes in this PR. Informs cockroachdb#157757. Epic: CRDB-55052 Co-authored-by: Tobias Grieger <[email protected]>
2 parents 682dc8c + d236fa5 commit 4c8e2ec

File tree

1 file changed

+242
-221
lines changed

1 file changed

+242
-221
lines changed

0 commit comments

Comments
 (0)