Skip to content

Commit a2487aa

Browse files
committed
kvserver: add LBRebalancingMultiMetricAndCount
This commit removes the cluster setting DisableCountBasedRebalancingIfMMAEnabled, renames LBRebalancingMultiMetric to LBRebalancingMultiMetricOnly, and introduces a new mode: LBRebalancingMultiMetricAndCount. To keep the datadriven test output unchanged, all previous references to mma in asim now use LBRebalancingMultiMetricAndCount, which matches the prior behavior. I’ll follow up with a new asim mode in future commits.
1 parent 2443eee commit a2487aa

File tree

11 files changed

+42
-36
lines changed

11 files changed

+42
-36
lines changed

docs/generated/settings/settings.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
<tr><td><div id="setting-jobs-retention-time" class="anchored"><code>jobs.retention_time</code></div></td><td>duration</td><td><code>336h0m0s</code></td><td>the amount of time for which records for completed jobs are retained</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
8787
<tr><td><div id="setting-kv-allocator-lease-rebalance-threshold" class="anchored"><code>kv.allocator.lease_rebalance_threshold</code></div></td><td>float</td><td><code>0.05</code></td><td>minimum fraction away from the mean a store&#39;s lease count can be before it is considered for lease-transfers</td><td>Advanced/Self-Hosted</td></tr>
8888
<tr><td><div id="setting-kv-allocator-load-based-lease-rebalancing-enabled" class="anchored"><code>kv.allocator.load_based_lease_rebalancing.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>set to enable rebalancing of range leases based on load and latency</td><td>Advanced/Self-Hosted</td></tr>
89-
<tr><td><div id="setting-kv-allocator-load-based-rebalancing" class="anchored"><code>kv.allocator.load_based_rebalancing</code></div></td><td>enumeration</td><td><code>leases and replicas</code></td><td>whether to rebalance based on the distribution of load across stores [off = 0, leases = 1, leases and replicas = 2, multi-metric = 3]</td><td>Advanced/Self-Hosted</td></tr>
89+
<tr><td><div id="setting-kv-allocator-load-based-rebalancing" class="anchored"><code>kv.allocator.load_based_rebalancing</code></div></td><td>enumeration</td><td><code>leases and replicas</code></td><td>whether to rebalance based on the distribution of load across stores [off = 0, leases = 1, leases and replicas = 2, multi-metric = 3, multi-metric and count = 4]</td><td>Advanced/Self-Hosted</td></tr>
9090
<tr><td><div id="setting-kv-allocator-load-based-rebalancing-objective" class="anchored"><code>kv.allocator.load_based_rebalancing.objective</code></div></td><td>enumeration</td><td><code>cpu</code></td><td>what objective does the cluster use to rebalance; if set to `qps` the cluster will attempt to balance qps among stores, if set to `cpu` the cluster will attempt to balance cpu usage among stores [qps = 0, cpu = 1]</td><td>Advanced/Self-Hosted</td></tr>
9191
<tr><td><div id="setting-kv-allocator-load-based-rebalancing-interval" class="anchored"><code>kv.allocator.load_based_rebalancing_interval</code></div></td><td>duration</td><td><code>1m0s</code></td><td>the rough interval at which each store will check for load-based lease / replica rebalancing opportunities</td><td>Advanced/Self-Hosted</td></tr>
9292
<tr><td><div id="setting-kv-allocator-qps-rebalance-threshold" class="anchored"><code>kv.allocator.qps_rebalance_threshold</code></div></td><td>float</td><td><code>0.1</code></td><td>minimum fraction away from the mean a store&#39;s QPS (such as queries per second) can be before it is considered overfull or underfull</td><td>Advanced/Self-Hosted</td></tr>

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,12 +2744,12 @@ func (t TransferLeaseDecision) String() string {
27442744
}
27452745
}
27462746

2747-
// CountBasedRebalanceDisabled returns true if the count based rebalancing
2748-
// should be disabled. Disabled DisableCountBasedRebalancingIfMMAEnabled is true
2749-
// and mma is enabled (LBRebalancingMultiMetric).
2750-
func (a *Allocator) CountBasedRebalanceDisabled() bool {
2751-
return kvserverbase.DisableCountBasedRebalancingIfMMAEnabled.Get(&a.st.SV) &&
2752-
kvserverbase.LoadBasedRebalancingMode.Get(&a.st.SV) == kvserverbase.LBRebalancingMultiMetric
2747+
// CountBasedRebalancingDisabled returns true if count-based rebalancing should
2748+
// be disabled. Count-based rebalancing is disabled only when
2749+
// LBRebalancingMultiMetricOnly mode is active. To enable both multi-metric and
2750+
// count-based rebalancing, use LBRebalancingMultiMetricAndCount mode instead.
2751+
func (a *Allocator) CountBasedRebalancingDisabled() bool {
2752+
return kvserverbase.LoadBasedRebalancingMode.Get(&a.st.SV) == kvserverbase.LBRebalancingMultiMetricOnly
27532753
}
27542754

27552755
// ShouldTransferLease returns true if the specified store is overfull in terms
@@ -3052,7 +3052,7 @@ func (a Allocator) shouldTransferLeaseForLeaseCountConvergence(
30523052
existing []roachpb.ReplicaDescriptor,
30533053
) bool {
30543054
// Return false early if count based rebalancing is disabled.
3055-
if a.CountBasedRebalanceDisabled() {
3055+
if a.CountBasedRebalancingDisabled() {
30563056
return false
30573057
}
30583058
// TODO(a-robinson): Should we disable this behavior when load-based lease

pkg/kv/kvserver/allocator/plan/replicate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (rp ReplicaPlanner) ShouldPlanChange(
168168
nonVoterReplicas := desc.Replicas().NonVoterDescriptors()
169169
if !rp.knobs.DisableReplicaRebalancing {
170170
scorerOptions := allocatorimpl.ScorerOptions(rp.allocator.ScorerOptions(ctx))
171-
if rp.allocator.CountBasedRebalanceDisabled() {
171+
if rp.allocator.CountBasedRebalancingDisabled() {
172172
scorerOptions = rp.allocator.BaseScorerOptionsWithNoConvergence()
173173
}
174174
rangeUsageInfo := repl.RangeUsageInfo()
@@ -793,7 +793,7 @@ func (rp ReplicaPlanner) considerRebalance(
793793
if scatter {
794794
scorerOpts = rp.allocator.ScorerOptionsForScatter(ctx)
795795
}
796-
if rp.allocator.CountBasedRebalanceDisabled() {
796+
if rp.allocator.CountBasedRebalancingDisabled() {
797797
scorerOpts = rp.allocator.BaseScorerOptionsWithNoConvergence()
798798
}
799799
rangeUsageInfo := repl.RangeUsageInfo()

pkg/kv/kvserver/asim/mmaintegration/mma_store_rebalancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (msr *MMAStoreRebalancer) Tick(ctx context.Context, tick time.Time, s state
9797
return
9898
}
9999

100-
if kvserverbase.LoadBasedRebalancingMode.Get(&msr.settings.ST.SV) != kvserverbase.LBRebalancingMultiMetric {
100+
if !kvserverbase.LoadBasedRebalancingModeIsMMA(&msr.settings.ST.SV) {
101101
// When the store rebalancer isn't set to use the multi-metric mode, the
102102
// legacy store rebalancer is used.
103103
return

pkg/kv/kvserver/asim/tests/datadriven_simulation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func TestDataDriven(t *testing.T) {
495495
event.SetSimulationSettingsEvent{
496496
IsClusterSetting: true,
497497
Key: "LBRebalancingMode",
498-
Value: int64(kvserverbase.LBRebalancingMultiMetric),
498+
Value: int64(kvserverbase.LBRebalancingMultiMetricAndCount),
499499
})
500500
},
501501
// Both the replicate/lease queues and the MMA are enabled.
@@ -506,7 +506,7 @@ func TestDataDriven(t *testing.T) {
506506
event.SetSimulationSettingsEvent{
507507
IsClusterSetting: true,
508508
Key: "LBRebalancingMode",
509-
Value: int64(kvserverbase.LBRebalancingMultiMetric),
509+
Value: int64(kvserverbase.LBRebalancingMultiMetricAndCount),
510510
})
511511
},
512512
}

pkg/kv/kvserver/asim/tests/testdata/non_rand/load_distribution_movement_disabled_enable_later.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ gen_load rate=10000 rw_ratio=0 min_block=1000 max_block=1000 min_key=10001 max_k
3939
----
4040

4141
# Two minutes into the test, we'll enable the MMA.
42-
setting rebalance_mode=3 delay=2m
42+
setting rebalance_mode=4 delay=2m
4343
----
4444

4545
eval duration=7m samples=1 seed=42 cfgs=(sma-only) metrics=(cpu,write_bytes_per_second,replicas,leases)

pkg/kv/kvserver/kvserverbase/base.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ var LoadBasedRebalancingMode = settings.RegisterEnumSetting(
126126
"whether to rebalance based on the distribution of load across stores",
127127
"leases and replicas",
128128
map[LBRebalancingMode]string{
129-
LBRebalancingOff: "off",
130-
LBRebalancingLeasesOnly: "leases",
131-
LBRebalancingLeasesAndReplicas: "leases and replicas",
132-
LBRebalancingMultiMetric: "multi-metric",
129+
LBRebalancingOff: "off",
130+
LBRebalancingLeasesOnly: "leases",
131+
LBRebalancingLeasesAndReplicas: "leases and replicas",
132+
LBRebalancingMultiMetricOnly: "multi-metric",
133+
LBRebalancingMultiMetricAndCount: "multi-metric and count",
133134
},
134135
settings.WithPublic,
135136
settings.WithValidateEnum(func(enumStr string) error {
@@ -141,6 +142,13 @@ var LoadBasedRebalancingMode = settings.RegisterEnumSetting(
141142
}),
142143
)
143144

145+
// LoadBasedRebalancingModeIsMMA returns true if the load-based rebalancing mode
146+
// uses the multi-metric store rebalancer.
147+
var LoadBasedRebalancingModeIsMMA = func(sv *settings.Values) bool {
148+
mode := LoadBasedRebalancingMode.Get(sv)
149+
return mode == LBRebalancingMultiMetricOnly || mode == LBRebalancingMultiMetricAndCount
150+
}
151+
144152
// LBRebalancingMode controls if and when we do store-level rebalancing
145153
// based on load.
146154
type LBRebalancingMode int64
@@ -155,20 +163,17 @@ const (
155163
// LBRebalancingLeasesAndReplicas means that we rebalance both leases and
156164
// replicas based on store-level load imbalances.
157165
LBRebalancingLeasesAndReplicas
158-
// LBRebalancingMultiMetric means that the store rebalancer yields to the
166+
// LBRebalancingMultiMetricOnly means that the store rebalancer yields to the
159167
// multi-metric store rebalancer, balancing both leases and replicas based on
160-
// store-level load imbalances.
161-
LBRebalancingMultiMetric
162-
)
163-
164-
// DisableCountBasedRebalancingIfMMAEnabled is a setting that controls whether
165-
// to disable replica and lease count based rebalancing if multi-metric
166-
// allocator is enabled.
167-
var DisableCountBasedRebalancingIfMMAEnabled = settings.RegisterBoolSetting(
168-
settings.SystemOnly,
169-
"kv.allocator.disable_count_based_rebalancing_with_mma.enabled",
170-
"whether to disable replica and lease count based rebalancing if multi-metric allocator is enabled",
171-
false,
168+
// store-level load imbalances. Note that this disables replica-count and
169+
// lease-count based rebalancing.
170+
LBRebalancingMultiMetricOnly
171+
// LBRebalancingMultiMetricAndCount means that both multi-metric store
172+
// rebalancer and count based rebalancing via lease queue and replicate queue
173+
// are enabled, balancing lease count, replica count, and store-level load
174+
// across stores. Note that this might cause more thrashing since lease and
175+
// replica counts goal may be in conflict with the store-level load goal.
176+
LBRebalancingMultiMetricAndCount
172177
)
173178

174179
// RangeFeedRefreshInterval is injected from kvserver to avoid import cycles

pkg/kv/kvserver/mma_store_rebalancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (m *mmaStoreRebalancer) run(ctx context.Context, stopper *stop.Stopper) {
8181
// Wait out the first tick before doing anything since the store is still
8282
// starting up and we might as well wait for some stats to accumulate.
8383
timer.Reset(jitteredInterval(allocator.LoadBasedRebalanceInterval.Get(&m.st.SV)))
84-
if kvserverbase.LoadBasedRebalancingMode.Get(&m.st.SV) != kvserverbase.LBRebalancingMultiMetric {
84+
if !kvserverbase.LoadBasedRebalancingModeIsMMA(&m.st.SV) {
8585
continue
8686
}
8787

pkg/kv/kvserver/mmaintegration/allocator_sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (as *AllocatorSync) NonMMAPreTransferLease(
133133
transferFrom, transferTo roachpb.ReplicationTarget,
134134
) SyncChangeID {
135135
var changeIDs []mmaprototype.ChangeID
136-
if kvserverbase.LoadBasedRebalancingMode.Get(&as.st.SV) == kvserverbase.LBRebalancingMultiMetric {
136+
if kvserverbase.LoadBasedRebalancingModeIsMMA(&as.st.SV) {
137137
changeIDs = as.mmaAllocator.RegisterExternalChanges(convertLeaseTransferToMMA(desc, usage, transferFrom, transferTo))
138138
}
139139
trackedChange := trackedAllocatorChange{
@@ -158,7 +158,7 @@ func (as *AllocatorSync) NonMMAPreChangeReplicas(
158158
leaseholderStoreID roachpb.StoreID,
159159
) SyncChangeID {
160160
var changeIDs []mmaprototype.ChangeID
161-
if kvserverbase.LoadBasedRebalancingMode.Get(&as.st.SV) == kvserverbase.LBRebalancingMultiMetric {
161+
if kvserverbase.LoadBasedRebalancingModeIsMMA(&as.st.SV) {
162162
changeIDs = as.mmaAllocator.RegisterExternalChanges(convertReplicaChangeToMMA(desc, usage, changes, leaseholderStoreID))
163163
}
164164
trackedChange := trackedAllocatorChange{

pkg/kv/kvserver/store.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,8 @@ type StoreConfig struct {
11831183
StoreLiveness *storeliveness.NodeContainer
11841184
StorePool *storepool.StorePool
11851185
// One MMAllocator per node which guides mma store rebalancer to make
1186-
// allocation changes when LBRebalancingMultiMetric is enabled.
1186+
// allocation changes when
1187+
// LBRebalancingMultiMetricOnly/LBRebalancingMultiMetricAndCount is enabled.
11871188
MMAllocator mmaprototype.Allocator
11881189
AllocatorSync *mmaintegration.AllocatorSync
11891190
Transport *RaftTransport

0 commit comments

Comments
 (0)