Skip to content

Commit 6e2b0aa

Browse files
committed
allocatorimpl: populate advisor under rebalanceOptions
Previously, `bestRebalanceTarget` took a map and populated it with (option index->advisor) during the loop. This commit changes it to populate the advisor directly within the `rebalanceOptions` struct as a field.
1 parent 1e1e53d commit 6e2b0aa

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
1818
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator"
1919
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/load"
20-
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/mmaprototype"
2120
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/storepool"
2221
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/constraint"
2322
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvflowcontrol/rac2"
@@ -1890,11 +1889,10 @@ func (a Allocator) RebalanceTarget(
18901889
// to compute the means for the original set {s1, s2, s3} ∪ {existing} once
18911890
// and then use it for all calls to MMA, and bestRebalanceTarget does not need
18921891
// to copy the candidate set.
1893-
advisors := make(map[int]*mmaprototype.MMARebalanceAdvisor, len(results))
18941892
var bestIdx int
18951893

18961894
for {
1897-
target, existingCandidate, bestIdx = bestRebalanceTarget(a.randGen, results, a.as, advisors)
1895+
target, existingCandidate, bestIdx = bestRebalanceTarget(a.randGen, results, a.as)
18981896
if target == nil {
18991897
return zero, zero, "", false
19001898
}
@@ -1912,7 +1910,7 @@ func (a Allocator) RebalanceTarget(
19121910
// rebalance, we will continue to the next target. Note that this target
19131911
// would have been deleted from the candidates set in bestRebalanceTarget,
19141912
// so we will not select it again.
1915-
if advisor, ok := advisors[bestIdx]; ok {
1913+
if advisor := results[bestIdx].advisor; advisor != nil {
19161914
if a.as.IsInConflictWithMMA(target.store.StoreID, advisor, false) {
19171915
continue
19181916
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ func candidateListForRemoval(
14201420
type rebalanceOptions struct {
14211421
existing candidate
14221422
candidates candidateList
1423+
advisor *mmaprototype.MMARebalanceAdvisor
14231424
}
14241425

14251426
// equivalenceClass captures the set of "equivalent" replacement candidates
@@ -1929,10 +1930,7 @@ func rankedCandidateListForRebalancing(
19291930
// Contract: responsible for making sure that the returned bestIdx has the
19301931
// corresponding MMA advisor in advisors.
19311932
func bestRebalanceTarget(
1932-
randGen allocatorRand,
1933-
options []rebalanceOptions,
1934-
as *mmaintegration.AllocatorSync,
1935-
advisors map[int]*mmaprototype.MMARebalanceAdvisor,
1933+
randGen allocatorRand, options []rebalanceOptions, as *mmaintegration.AllocatorSync,
19361934
) (target, existingCandidate *candidate, bestIdx int) {
19371935
bestIdx = -1
19381936
var bestTarget *candidate
@@ -1957,12 +1955,12 @@ func bestRebalanceTarget(
19571955
}
19581956
// For the first time an option in options is selected, build and cache the
19591957
// corresponding MMA advisor in advisors[bestIdx].
1960-
if _, ok := advisors[bestIdx]; !ok {
1958+
if options[bestIdx].advisor == nil {
19611959
stores := make([]roachpb.StoreID, 0, len(options[bestIdx].candidates))
19621960
for _, cand := range options[bestIdx].candidates {
19631961
stores = append(stores, cand.store.StoreID)
19641962
}
1965-
advisors[bestIdx] = as.BuildMMARebalanceAdvisor(options[bestIdx].existing.store.StoreID, stores)
1963+
options[bestIdx].advisor = as.BuildMMARebalanceAdvisor(options[bestIdx].existing.store.StoreID, stores)
19661964
}
19671965

19681966
// Copy the selected target out of the candidates slice before modifying

0 commit comments

Comments
 (0)