Skip to content

Commit 263b219

Browse files
committed
mmaprototype: lazily initialize existingStoreSLS
Previously, `MMARebalanceAdvisor` built `existingStoreSLS` during `BuildMMARebalanceAdvisor`. This commit changes it to store only `existingStoreID` at `BuildMMARebalanceAdvisor`, and construct the actual `existingStoreSLS` during the first call to `IsInConflictWithMMA`. This has two advantages: (1) `existingStoreID` is now part of the advisor struct, making it available for logging in `IsInConflictWithMMA`; and (2) only `IsInConflictWithMMA` needs a context for logging, which makes sense for it to have one.
1 parent 6e2b0aa commit 263b219

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,9 +1301,10 @@ func (a *allocatorState) ensureAnalyzedConstraints(rstate *rangeState) bool {
13011301
type MMARebalanceAdvisor struct {
13021302
// disabled is true when MMA is disabled. It overrides all decisions with
13031303
// IsInConflictWithMMA returning false.
1304-
disabled bool
1304+
disabled bool
1305+
existingStoreID roachpb.StoreID
13051306
// existingStoreSLS is the load summary for the existing store.
1306-
existingStoreSLS storeLoadSummary
1307+
existingStoreSLS *storeLoadSummary
13071308
// means is the means for the candidate set.
13081309
means meansLoad
13091310
}
@@ -1331,12 +1332,9 @@ func (a *allocatorState) BuildMMARebalanceAdvisor(
13311332
scratchStores := map[roachpb.StoreID]struct{}{}
13321333
cands = append(cands, existing)
13331334
means := computeMeansForStoreSet(a.cs, cands, scratchNodes, scratchStores)
1334-
// TODO(wenyihu6): pass in the actual ctx here
1335-
existingSLS := a.cs.computeLoadSummary(context.Background(), existing,
1336-
&means.storeLoad, &means.nodeLoad)
13371335
return &MMARebalanceAdvisor{
1338-
existingStoreSLS: existingSLS,
1339-
means: means,
1336+
existingStoreID: existing,
1337+
means: means,
13401338
}
13411339
}
13421340

@@ -1350,8 +1348,14 @@ func (a *allocatorState) IsInConflictWithMMA(
13501348
if advisor.disabled {
13511349
return false
13521350
}
1353-
candSLS := a.cs.computeLoadSummary(context.Background(), cand, &advisor.means.storeLoad, &advisor.means.nodeLoad)
1351+
if advisor.existingStoreSLS == nil {
1352+
// TODO(wenyihu6): pass in the actual ctx here
1353+
summary := a.cs.computeLoadSummary(context.Background(), advisor.existingStoreID,
1354+
&advisor.means.storeLoad, &advisor.means.nodeLoad)
1355+
advisor.existingStoreSLS = &summary
1356+
}
13541357
existingSLS := advisor.existingStoreSLS
1358+
candSLS := a.cs.computeLoadSummary(context.Background(), cand, &advisor.means.storeLoad, &advisor.means.nodeLoad)
13551359
if cpuOnly {
13561360
return candSLS.dimSummary[CPURate] > existingSLS.dimSummary[CPURate]
13571361
}

0 commit comments

Comments
 (0)