Skip to content

Commit 05e0e07

Browse files
committed
allocator: add option to disable lease-count based rebalancing
This commit disables lease-count based rebalancing in the lease queue if CountBasedRebalanceDisabled is true. Currently, the lease queue uses `ShouldTransferLease` and `PlanOneChange` to select a target store for transferring a range lease. Candidate stores are chosen based on store health, lease preferences, lagging replicas, and I/O load, and the final target is decided using one of: `FollowTheWorkload`, `LeaseCountConvergence`, or `LoadConvergence`. `LeaseCountConvergence` is used in two scenarios: (1) When `FollowTheWorkload` (`shouldTransferLeaseForAccessLocality`) lacks sufficient stats or locality info. (2) `maybeTransferLeaseAwayTarget`: calls into `allocator.TransferLeaseTarget` with `LeaseCountConvergence` directly. This commit disables case (1) by returning early in `shouldTransferLeaseForLeaseCountConvergence` (used in `Allocator.TransferLeaseTarget` and `allocator.ShouldTransferLease`). Case (2) is left intact, since it is less common and less likely to interfere with MMA decisions.
1 parent 95f22f0 commit 05e0e07

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/kv/kvserver/allocator/allocatorimpl/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ go_library(
1818
"//pkg/kv/kvserver/allocator/storepool",
1919
"//pkg/kv/kvserver/constraint",
2020
"//pkg/kv/kvserver/kvflowcontrol/rac2",
21+
"//pkg/kv/kvserver/kvserverbase",
2122
"//pkg/kv/kvserver/liveness",
2223
"//pkg/kv/kvserver/liveness/livenesspb",
2324
"//pkg/kv/kvserver/raftutil",

pkg/kv/kvserver/allocator/allocatorimpl/allocator.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/storepool"
2121
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/constraint"
2222
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvflowcontrol/rac2"
23+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase"
2324
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/raftutil"
2425
"github.com/cockroachdb/cockroach/pkg/raft"
2526
"github.com/cockroachdb/cockroach/pkg/raft/raftpb"
@@ -2725,6 +2726,14 @@ func (t TransferLeaseDecision) String() string {
27252726
}
27262727
}
27272728

2729+
// CountBasedRebalanceDisabled returns true if the count based rebalancing
2730+
// should be disabled. Disabled DisableCountBasedRebalancingIfMMAEnabled is true
2731+
// and mma is enabled (LBRebalancingMultiMetric).
2732+
func (a *Allocator) CountBasedRebalanceDisabled() bool {
2733+
return kvserverbase.DisableCountBasedRebalancingIfMMAEnabled.Get(&a.st.SV) &&
2734+
kvserverbase.LoadBasedRebalancingMode.Get(&a.st.SV) == kvserverbase.LBRebalancingMultiMetric
2735+
}
2736+
27282737
// ShouldTransferLease returns true if the specified store is overfull in terms
27292738
// of leases with respect to the other stores matching the specified
27302739
// attributes.
@@ -3024,6 +3033,10 @@ func (a Allocator) shouldTransferLeaseForLeaseCountConvergence(
30243033
source roachpb.StoreDescriptor,
30253034
existing []roachpb.ReplicaDescriptor,
30263035
) bool {
3036+
// Return false early if count based rebalancing is disabled.
3037+
if a.CountBasedRebalanceDisabled() {
3038+
return false
3039+
}
30273040
// TODO(a-robinson): Should we disable this behavior when load-based lease
30283041
// rebalancing is enabled? In happy cases it's nice to keep this working
30293042
// to even out the number of leases in addition to the number of replicas,

0 commit comments

Comments
 (0)