Skip to content

Commit 1e1e53d

Browse files
committed
mmaprototype: return a pointer for BuildMMARebalanceAdvisor
This commit updates BuildMMARebalanceAdvisor to return a pointer, since future changes will require passing it around and modifying its fields.
1 parent 5d3aad9 commit 1e1e53d

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ func (a Allocator) RebalanceTarget(
18901890
// to compute the means for the original set {s1, s2, s3} ∪ {existing} once
18911891
// and then use it for all calls to MMA, and bestRebalanceTarget does not need
18921892
// to copy the candidate set.
1893-
advisors := make(map[int]mmaprototype.MMARebalanceAdvisor, len(results))
1893+
advisors := make(map[int]*mmaprototype.MMARebalanceAdvisor, len(results))
18941894
var bestIdx int
18951895

18961896
for {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ func bestRebalanceTarget(
19321932
randGen allocatorRand,
19331933
options []rebalanceOptions,
19341934
as *mmaintegration.AllocatorSync,
1935-
advisors map[int]mmaprototype.MMARebalanceAdvisor,
1935+
advisors map[int]*mmaprototype.MMARebalanceAdvisor,
19361936
) (target, existingCandidate *candidate, bestIdx int) {
19371937
bestIdx = -1
19381938
var bestTarget *candidate

pkg/kv/kvserver/allocator/mmaprototype/allocator_state.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,8 +1311,8 @@ type MMARebalanceAdvisor struct {
13111311
// NoopMMARebalanceAdvisor is a no-op MMARebalanceAdvisor that always returns
13121312
// false for IsInConflictWithMMA. Used when MMA is disabled or mma does not have
13131313
// enough information to determine.
1314-
func NoopMMARebalanceAdvisor() MMARebalanceAdvisor {
1315-
return MMARebalanceAdvisor{
1314+
func NoopMMARebalanceAdvisor() *MMARebalanceAdvisor {
1315+
return &MMARebalanceAdvisor{
13161316
disabled: true,
13171317
}
13181318
}
@@ -1324,7 +1324,7 @@ func NoopMMARebalanceAdvisor() MMARebalanceAdvisor {
13241324
// existing store. mma should include the existing store in the candidate set.
13251325
func (a *allocatorState) BuildMMARebalanceAdvisor(
13261326
existing roachpb.StoreID, cands []roachpb.StoreID,
1327-
) MMARebalanceAdvisor {
1327+
) *MMARebalanceAdvisor {
13281328
// TODO(wenyihu6): for simplicity, we create a new scratchNodes every call.
13291329
// We should reuse the scratchNodes instead.
13301330
scratchNodes := map[roachpb.NodeID]*NodeLoad{}
@@ -1334,7 +1334,7 @@ func (a *allocatorState) BuildMMARebalanceAdvisor(
13341334
// TODO(wenyihu6): pass in the actual ctx here
13351335
existingSLS := a.cs.computeLoadSummary(context.Background(), existing,
13361336
&means.storeLoad, &means.nodeLoad)
1337-
return MMARebalanceAdvisor{
1337+
return &MMARebalanceAdvisor{
13381338
existingStoreSLS: existingSLS,
13391339
means: means,
13401340
}
@@ -1345,7 +1345,7 @@ func (a *allocatorState) BuildMMARebalanceAdvisor(
13451345
// for making sure the MMARebalanceAdvisor is for the correct existing store and
13461346
// candidate set.
13471347
func (a *allocatorState) IsInConflictWithMMA(
1348-
cand roachpb.StoreID, advisor MMARebalanceAdvisor, cpuOnly bool,
1348+
cand roachpb.StoreID, advisor *MMARebalanceAdvisor, cpuOnly bool,
13491349
) bool {
13501350
if advisor.disabled {
13511351
return false

pkg/kv/kvserver/mmaintegration/allocator_sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ type mmaState interface {
4949
// MMARebalanceAdvisor for the given existing store and candidates. The
5050
// advisor should be later passed to IsInConflictWithMMA to determine if a
5151
// given candidate is in conflict with the existing store.
52-
BuildMMARebalanceAdvisor(existing roachpb.StoreID, cands []roachpb.StoreID) mmaprototype.MMARebalanceAdvisor
52+
BuildMMARebalanceAdvisor(existing roachpb.StoreID, cands []roachpb.StoreID) *mmaprototype.MMARebalanceAdvisor
5353
// IsInConflictWithMMA is called by the allocator sync to determine if the
5454
// given candidate is in conflict with the existing store.
55-
IsInConflictWithMMA(cand roachpb.StoreID, advisor mmaprototype.MMARebalanceAdvisor, cpuOnly bool) bool
55+
IsInConflictWithMMA(cand roachpb.StoreID, advisor *mmaprototype.MMARebalanceAdvisor, cpuOnly bool) bool
5656
}
5757

5858
// TODO(wenyihu6): make sure allocator sync can tolerate cluster setting

pkg/kv/kvserver/mmaintegration/thrashing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ import (
9292
// and associating it with the corresponding existing store.
9393
func (as *AllocatorSync) BuildMMARebalanceAdvisor(
9494
existing roachpb.StoreID, cands []roachpb.StoreID,
95-
) mmaprototype.MMARebalanceAdvisor {
95+
) *mmaprototype.MMARebalanceAdvisor {
9696
if kvserverbase.LoadBasedRebalancingMode.Get(&as.st.SV) != kvserverbase.LBRebalancingMultiMetricAndCount {
9797
return mmaprototype.NoopMMARebalanceAdvisor()
9898
}
@@ -101,7 +101,7 @@ func (as *AllocatorSync) BuildMMARebalanceAdvisor(
101101

102102
// IsInConflictWithMMA determines if a candidate conflicts with MMA's goals.
103103
func (as *AllocatorSync) IsInConflictWithMMA(
104-
cand roachpb.StoreID, advisor mmaprototype.MMARebalanceAdvisor, cpuOnly bool,
104+
cand roachpb.StoreID, advisor *mmaprototype.MMARebalanceAdvisor, cpuOnly bool,
105105
) bool {
106106
if as.knobs != nil && as.knobs.OverrideIsInConflictWithMMA != nil {
107107
return as.knobs.OverrideIsInConflictWithMMA(cand)

0 commit comments

Comments
 (0)