Skip to content

Commit 7fdf860

Browse files
craig[bot]wenyihu6
andcommitted
Merge #153220
153220: kvserverbase: add DisableCountBasedRebalancingIfMMAEnabled r=tbg a=wenyihu6 Resolves: #152579 Release note: none --- **kvserverbase: add DisableCountBasedRebalancingIfMMAEnabled** This commit introduces a new cluster setting, `DisableCountBasedRebalancingIfMMAEnabled`, which allows us to disable range-count and lease-count based convergence rebalancing when mma is enabled. These forms of rebalancing can conflict with mma goals and cause thrashing. --- **allocator: add option to disable lease-count based rebalancing** This commit disables lease-count based rebalancing in the lease queue. 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. --- **kvserver: add `BaseScorerOptions`** This commit introduces `BaseScorerOptions`, a base struct embedded by other `ScorerOptions` implementations. It provides the default implementation methods, while specific implementations can override individual methods to apply their own scoring heuristics. --- **allocator: add `adjustRangeCountForScoring`** This commit adds `adjustRangeCountForScoring` to the `ScorerOptions` interface. The method takes a provided range count, adjusts it according to the scorer’s heuristic, and returns the result. It is similar to other scoring metrics such as the convergence score, and will later be used in candidate.compare as an attribute for breaking ties. The compare method evaluates the relative difference between two stores and favors the one with fewer ranges as a better rebalance target. Currently and by default, `adjustRangeCountForScoring` simply returns the provided range count. Future scorer options will override it with 0 since the heuristics is to not consider range count at all. --- **allocator: add `BaseScorerOptionsNoConvergence`** This commit disables range-count based rebalancing. Currently, when selecting a rebalance target, the allocator constructs an equivalence class for each existing replica. This class includes all stores that are not worse than the existing replica in terms of constraint conformance, diversity score, and disk fullness. At this stage, range count convergence is not yet considered. The allocator then evaluates each candidate set using `ScorerOptions`, which populates candidates' attributes such as balance score, convergence score, and range count with respect to the equivalence class, and determines the best candidate within each equivalence class. To disable range count–based rebalancing, this commit introduces a new scorer option, `BaseScorerOptionsNoConvergence`. This scorer assigns the same score to all stores, effectively treating candidates within the same equivalence class the same. It is only used when both MMA and `DisableCountBasedRebalancingIfMMAEnabled` are enabled. Note that this new scorer option is applied only in `ReplicaPlanner.considerRebalance` and `ReplicaPlanner.ShouldPlanChange`. As a result, range-count based rebalancing is disabled during rebalancing, but range count is still considered when allocator adds new replicas (such as `AllocateVoter`), choosing a rebalance target in the old store rebalancer (`StoreRebalancer.applyRangeRebalance`), and when removing replicas (`Allocator.RemoveVoter`). --- **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. Co-authored-by: wenyihu6 <[email protected]>
2 parents 191e4a1 + a2487aa commit 7fdf860

File tree

17 files changed

+229
-96
lines changed

17 files changed

+229
-96
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/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: 40 additions & 9 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"
@@ -2055,20 +2056,36 @@ func (a Allocator) RebalanceNonVoter(
20552056
// machinery to achieve range count convergence.
20562057
func (a *Allocator) ScorerOptions(ctx context.Context) *RangeCountScorerOptions {
20572058
return &RangeCountScorerOptions{
2058-
IOOverloadOptions: a.IOOverloadOptions(),
2059-
DiskCapacityOptions: a.DiskOptions(),
2060-
deterministic: a.deterministic,
2059+
BaseScorerOptions: BaseScorerOptions{
2060+
IOOverload: a.IOOverloadOptions(),
2061+
DiskCapacity: a.DiskOptions(),
2062+
Deterministic: a.deterministic,
2063+
},
20612064
rangeRebalanceThreshold: RangeRebalanceThreshold.Get(&a.st.SV),
20622065
}
20632066
}
20642067

2068+
// BaseScorerOptionsWithNoConvergence returns the base scorer options with no
2069+
// convergence heuristics.
2070+
func (a *Allocator) BaseScorerOptionsWithNoConvergence() BaseScorerOptionsNoConvergence {
2071+
return BaseScorerOptionsNoConvergence{
2072+
BaseScorerOptions: BaseScorerOptions{
2073+
IOOverload: a.IOOverloadOptions(),
2074+
DiskCapacity: a.DiskOptions(),
2075+
Deterministic: a.deterministic,
2076+
},
2077+
}
2078+
}
2079+
20652080
// ScorerOptionsForScatter returns the scorer options for scattering purposes.
20662081
func (a *Allocator) ScorerOptionsForScatter(ctx context.Context) *ScatterScorerOptions {
20672082
return &ScatterScorerOptions{
20682083
RangeCountScorerOptions: RangeCountScorerOptions{
2069-
IOOverloadOptions: a.IOOverloadOptions(),
2070-
DiskCapacityOptions: a.DiskOptions(),
2071-
deterministic: a.deterministic,
2084+
BaseScorerOptions: BaseScorerOptions{
2085+
IOOverload: a.IOOverloadOptions(),
2086+
DiskCapacity: a.DiskOptions(),
2087+
Deterministic: a.deterministic,
2088+
},
20722089
rangeRebalanceThreshold: 0,
20732090
},
20742091
// We set jitter to be equal to the padding around replica-count rebalancing
@@ -2517,9 +2534,11 @@ func (a *Allocator) TransferLeaseTarget(
25172534
candidates,
25182535
storeDescMap,
25192536
&LoadScorerOptions{
2520-
IOOverloadOptions: a.IOOverloadOptions(),
2521-
DiskOptions: a.DiskOptions(),
2522-
Deterministic: a.deterministic,
2537+
BaseScorerOptions: BaseScorerOptions{
2538+
IOOverload: a.IOOverloadOptions(),
2539+
DiskCapacity: a.DiskOptions(),
2540+
Deterministic: a.deterministic,
2541+
},
25232542
LoadDims: opts.LoadDimensions,
25242543
LoadThreshold: LoadThresholds(&a.st.SV, opts.LoadDimensions...),
25252544
MinLoadThreshold: LoadMinThresholds(opts.LoadDimensions...),
@@ -2725,6 +2744,14 @@ func (t TransferLeaseDecision) String() string {
27252744
}
27262745
}
27272746

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
2753+
}
2754+
27282755
// ShouldTransferLease returns true if the specified store is overfull in terms
27292756
// of leases with respect to the other stores matching the specified
27302757
// attributes.
@@ -3024,6 +3051,10 @@ func (a Allocator) shouldTransferLeaseForLeaseCountConvergence(
30243051
source roachpb.StoreDescriptor,
30253052
existing []roachpb.ReplicaDescriptor,
30263053
) bool {
3054+
// Return false early if count based rebalancing is disabled.
3055+
if a.CountBasedRebalancingDisabled() {
3056+
return false
3057+
}
30273058
// TODO(a-robinson): Should we disable this behavior when load-based lease
30283059
// rebalancing is enabled? In happy cases it's nice to keep this working
30293060
// to even out the number of leases in addition to the number of replicas,

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

Lines changed: 114 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@ type ScorerOptions interface {
292292
// the store represented by `sc` classifies as underfull, aroundTheMean, or
293293
// overfull relative to all the stores in `sl`.
294294
balanceScore(sl storepool.StoreList, sc roachpb.StoreCapacity) balanceStatus
295+
// adjustRangeCountForScoring returns the adjusted range count for scoring.
296+
// Scorer options (IOOverloadOnlyScorerOptions) that do not score based on
297+
// range count convergence returns 0. Otherwise, the returned range count here
298+
// should usually be the same as the range count passed in
299+
// (RangeCountScorerOptions, LoadScorerOptions, ScatterScorerOptions). This
300+
// will later be used to calculate the relative difference when comparing the
301+
// range count of the candidate stores. Lower range count means a better
302+
// candidate to move the replica to.
303+
adjustRangeCountForScoring(rangeCount int) int
295304
// rebalanceFromConvergenceScore assigns a convergence score to the store
296305
// referred to by `eqClass.existing` based on whether moving a replica away
297306
// from this store would converge its stats towards the mean (relative to the
@@ -342,10 +351,6 @@ type ScatterScorerOptions struct {
342351

343352
var _ ScorerOptions = &ScatterScorerOptions{}
344353

345-
func (o *ScatterScorerOptions) getIOOverloadOptions() IOOverloadOptions {
346-
return o.RangeCountScorerOptions.IOOverloadOptions
347-
}
348-
349354
func (o *ScatterScorerOptions) maybeJitterStoreStats(
350355
sl storepool.StoreList, allocRand allocatorRand,
351356
) (perturbedSL storepool.StoreList) {
@@ -360,37 +365,116 @@ func (o *ScatterScorerOptions) maybeJitterStoreStats(
360365
return storepool.MakeStoreList(perturbedStoreDescs)
361366
}
362367

363-
// RangeCountScorerOptions is used by the replicateQueue to tell the Allocator's
364-
// rebalancing machinery to base its balance/convergence scores on range counts.
365-
// This means that the resulting rebalancing decisions will further the goal of
366-
// converging range counts across stores in the cluster.
367-
type RangeCountScorerOptions struct {
368-
IOOverloadOptions
369-
DiskCapacityOptions
370-
deterministic bool
371-
rangeRebalanceThreshold float64
368+
// BaseScorerOptions is the base scorer options that is embedded in
369+
// every scorer option.
370+
type BaseScorerOptions struct {
371+
IOOverload IOOverloadOptions
372+
DiskCapacity DiskCapacityOptions
373+
Deterministic bool
372374
}
373375

374-
var _ ScorerOptions = &RangeCountScorerOptions{}
376+
func (bo BaseScorerOptions) getIOOverloadOptions() IOOverloadOptions {
377+
return bo.IOOverload
378+
}
375379

376-
func (o *RangeCountScorerOptions) getIOOverloadOptions() IOOverloadOptions {
377-
return o.IOOverloadOptions
380+
func (bo BaseScorerOptions) getDiskOptions() DiskCapacityOptions {
381+
return bo.DiskCapacity
378382
}
379383

380-
func (o *RangeCountScorerOptions) getDiskOptions() DiskCapacityOptions {
381-
return o.DiskCapacityOptions
384+
func (bo BaseScorerOptions) deterministicForTesting() bool {
385+
return bo.Deterministic
382386
}
383387

384-
func (o *RangeCountScorerOptions) maybeJitterStoreStats(
388+
// maybeJitterStoreStats returns the provided store list since that is the
389+
// default behavior. ScatterScorerOptions is the only scorer option that jitters
390+
// store stats to rebalance replicas across stores randomly.
391+
func (bo BaseScorerOptions) maybeJitterStoreStats(
385392
sl storepool.StoreList, _ allocatorRand,
386-
) (perturbedSL storepool.StoreList) {
393+
) storepool.StoreList {
387394
return sl
388395
}
389396

390-
func (o *RangeCountScorerOptions) deterministicForTesting() bool {
391-
return o.deterministic
397+
// adjustRangeCountForScoring returns the provided range count since that is the
398+
// default behavior. BaseScorerOptionsNoConvergence is the only scorer option
399+
// that does not want to consider range count in its scoring, so it returns 0.
400+
func (bo BaseScorerOptions) adjustRangeCountForScoring(rangeCount int) int {
401+
return rangeCount
402+
}
403+
404+
// BaseScorerOptionsNoConvergence is the base scorer options that does not
405+
// involve any heuristics or convergence scoring.
406+
//
407+
// It assigns the same score to all stores, effectively treating candidates
408+
// within the same equivalence class the same and disabling range-count based
409+
// convergence rebalancing.
410+
//
411+
// Note that this new scorer option is applied used in
412+
// ReplicaPlanner.considerRebalance and ReplicaPlanner.ShouldPlanChange. As a
413+
// result, range-count based rebalancing is disabled during rebalancing, but
414+
// range count is still considered when allocator adds new replicas (such as
415+
// AllocateVoter), choosing a rebalance target in the old store rebalancer
416+
// (StoreRebalancer.applyRangeRebalance), and when removing replicas
417+
// (Allocator.RemoveVoter).
418+
type BaseScorerOptionsNoConvergence struct {
419+
BaseScorerOptions
420+
}
421+
422+
var _ ScorerOptions = BaseScorerOptionsNoConvergence{}
423+
424+
// adjustRangeCountForScoring returns 0 since BaseScorerOptionsNoConvergence
425+
// does not want to consider range count in its scoring.
426+
func (bnc BaseScorerOptionsNoConvergence) adjustRangeCountForScoring(_ int) int {
427+
return 0
428+
}
429+
430+
// shouldRebalanceBasedOnThresholds returns false since
431+
// BaseScorerOptionsNoConvergence does not involve any heuristics that evaluate
432+
// stores within an equivalence class. If no rebalancing is needed based on
433+
// other attributes (e.g. valid, disk fullness, constraints, diversity score),
434+
// no rebalancing is done.
435+
func (bnc BaseScorerOptionsNoConvergence) shouldRebalanceBasedOnThresholds(
436+
_ context.Context, _ equivalenceClass, _ AllocatorMetrics,
437+
) bool {
438+
return false
439+
}
440+
441+
// balanceScore returns aroundTheMean for every store so that
442+
// BaseScorerOptionsNoConvergence does not take range count into account.
443+
func (bnc BaseScorerOptionsNoConvergence) balanceScore(
444+
_ storepool.StoreList, _ roachpb.StoreCapacity,
445+
) balanceStatus {
446+
return aroundTheMean
447+
}
448+
449+
// Note that the following three methods all return 0 for every store so that
450+
// BaseScorerOptionsNoConvergence does not take convergence score into account.
451+
// Important to keep them the same value since betterRebalanceTarget may compare
452+
// convergence score the difference between rebalanceFrom and rebalanceTo stores.
453+
func (bnc BaseScorerOptionsNoConvergence) rebalanceFromConvergesScore(_ equivalenceClass) int {
454+
return 0
455+
}
456+
func (bnc BaseScorerOptionsNoConvergence) rebalanceToConvergesScore(
457+
_ equivalenceClass, _ roachpb.StoreDescriptor,
458+
) int {
459+
return 0
460+
}
461+
func (bnc BaseScorerOptionsNoConvergence) removalMaximallyConvergesScore(
462+
_ storepool.StoreList, _ roachpb.StoreDescriptor,
463+
) int {
464+
return 0
392465
}
393466

467+
// RangeCountScorerOptions is used by the replicateQueue to tell the Allocator's
468+
// rebalancing machinery to base its balance/convergence scores on range counts.
469+
// This means that the resulting rebalancing decisions will further the goal of
470+
// converging range counts across stores in the cluster.
471+
type RangeCountScorerOptions struct {
472+
BaseScorerOptions
473+
rangeRebalanceThreshold float64
474+
}
475+
476+
var _ ScorerOptions = &RangeCountScorerOptions{}
477+
394478
func (o RangeCountScorerOptions) shouldRebalanceBasedOnThresholds(
395479
ctx context.Context, eqClass equivalenceClass, metrics AllocatorMetrics,
396480
) bool {
@@ -491,10 +575,8 @@ func (o *RangeCountScorerOptions) removalMaximallyConvergesScore(
491575
// queries-per-second. This means that the resulting rebalancing decisions will
492576
// further the goal of converging QPS across stores in the cluster.
493577
type LoadScorerOptions struct {
494-
IOOverloadOptions IOOverloadOptions
495-
DiskOptions DiskCapacityOptions
496-
Deterministic bool
497-
LoadDims []load.Dimension
578+
BaseScorerOptions
579+
LoadDims []load.Dimension
498580

499581
// LoadThreshold and MinLoadThreshold track the threshold beyond which a
500582
// store should be considered under/overfull and the minimum absolute
@@ -528,23 +610,7 @@ type LoadScorerOptions struct {
528610
RebalanceImpact load.Load
529611
}
530612

531-
func (o *LoadScorerOptions) getIOOverloadOptions() IOOverloadOptions {
532-
return o.IOOverloadOptions
533-
}
534-
535-
func (o *LoadScorerOptions) getDiskOptions() DiskCapacityOptions {
536-
return o.DiskOptions
537-
}
538-
539-
func (o *LoadScorerOptions) maybeJitterStoreStats(
540-
sl storepool.StoreList, _ allocatorRand,
541-
) storepool.StoreList {
542-
return sl
543-
}
544-
545-
func (o *LoadScorerOptions) deterministicForTesting() bool {
546-
return o.Deterministic
547-
}
613+
var _ ScorerOptions = &LoadScorerOptions{}
548614

549615
// shouldRebalanceBasedOnThresholds tries to determine if, within the given
550616
// equivalenceClass `eqClass`, rebalancing a replica from one of the existing
@@ -1168,14 +1234,15 @@ func rankedCandidateListForAllocation(
11681234
}
11691235
hasNonVoter = StoreHasReplica(s.StoreID, nonVoterReplTargets)
11701236
}
1237+
rangeCountScore := options.adjustRangeCountForScoring(int(s.Capacity.RangeCount))
11711238
candidates = append(candidates, candidate{
11721239
store: s,
11731240
necessary: necessary,
11741241
valid: constraintsOK,
11751242
diversityScore: diversityScore,
11761243
balanceScore: balanceScore,
11771244
hasNonVoter: hasNonVoter,
1178-
rangeCount: int(s.Capacity.RangeCount),
1245+
rangeCount: rangeCountScore,
11791246
})
11801247
}
11811248
if options.deterministicForTesting() {
@@ -1283,7 +1350,7 @@ func candidateListForRemoval(
12831350
candidates[i].balanceScore = options.balanceScore(
12841351
removalCandidateStoreList, candidates[i].store.Capacity,
12851352
)
1286-
candidates[i].rangeCount = int(candidates[i].store.Capacity.RangeCount)
1353+
candidates[i].rangeCount = options.adjustRangeCountForScoring(int(candidates[i].store.Capacity.RangeCount))
12871354
}
12881355
// Re-sort to account for the ordering changes resulting from the addition of
12891356
// convergesScore, balanceScore, etc.
@@ -1748,7 +1815,7 @@ func rankedCandidateListForRebalancing(
17481815
balanceScore := options.balanceScore(comparable.candidateSL, existing.store.Capacity)
17491816
existing.convergesScore = convergesScore
17501817
existing.balanceScore = balanceScore
1751-
existing.rangeCount = int(existing.store.Capacity.RangeCount)
1818+
existing.rangeCount = options.adjustRangeCountForScoring(int(existing.store.Capacity.RangeCount))
17521819
}
17531820

17541821
var candidates candidateList
@@ -1774,7 +1841,7 @@ func rankedCandidateListForRebalancing(
17741841
)
17751842
cand.balanceScore = options.balanceScore(comparable.candidateSL, s.Capacity)
17761843
cand.convergesScore = options.rebalanceToConvergesScore(comparable, s)
1777-
cand.rangeCount = int(s.Capacity.RangeCount)
1844+
cand.rangeCount = options.adjustRangeCountForScoring(int(s.Capacity.RangeCount))
17781845
candidates = append(candidates, cand)
17791846
}
17801847

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,9 @@ func TestShouldRebalanceDiversity(t *testing.T) {
15571557
defer log.Scope(t).Close(t)
15581558

15591559
options := &RangeCountScorerOptions{
1560-
DiskCapacityOptions: defaultDiskCapacityOptions(),
1560+
BaseScorerOptions: BaseScorerOptions{
1561+
DiskCapacity: defaultDiskCapacityOptions(),
1562+
},
15611563
}
15621564
newStore := func(id int, locality roachpb.Locality) roachpb.StoreDescriptor {
15631565
return roachpb.StoreDescriptor{
@@ -2008,7 +2010,9 @@ func TestBalanceScoreByRangeCount(t *testing.T) {
20082010
defer log.Scope(t).Close(t)
20092011

20102012
options := RangeCountScorerOptions{
2011-
DiskCapacityOptions: defaultDiskCapacityOptions(),
2013+
BaseScorerOptions: BaseScorerOptions{
2014+
DiskCapacity: defaultDiskCapacityOptions(),
2015+
},
20122016
rangeRebalanceThreshold: 0.1,
20132017
}
20142018
storeList := storepool.StoreList{
@@ -2094,7 +2098,9 @@ func TestRebalanceConvergesRangeCountOnMean(t *testing.T) {
20942098
}
20952099

20962100
options := RangeCountScorerOptions{
2097-
DiskCapacityOptions: defaultDiskCapacityOptions(),
2101+
BaseScorerOptions: BaseScorerOptions{
2102+
DiskCapacity: defaultDiskCapacityOptions(),
2103+
},
20982104
}
20992105
eqClass := equivalenceClass{
21002106
candidateSL: storeList,

0 commit comments

Comments
 (0)