Skip to content

Commit bbcb7d0

Browse files
committed
mmaprototype: pass []roachpb.StoreID for computeMeansForStoreSet
Previously, computeMeansForStoreSet took in a meansForStoreSet struct. Future PRs will use this helper function to compute mean load summaries for stores without having a storeIDPostingList handy. To avoid unnecessary construction of a storeIDPostingList, the function signature now takes meansLoad and []roachpb.StoreID directly. This change lets future callers pass a simple slice of stores. Since future callers may provide slices with duplicate store IDs, the function now also de-duplicates them internally.
1 parent 2a1771e commit bbcb7d0

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func (a *allocatorState) rebalanceStores(
476476
var means meansForStoreSet
477477
clear(scratchNodes)
478478
means.stores = candsPL
479-
computeMeansForStoreSet(a.cs, &means, scratchNodes)
479+
computeMeansForStoreSet(a.cs, &means.meansLoad, means.stores, scratchNodes)
480480
sls := a.cs.computeLoadSummary(ctx, store.StoreID, &means.storeLoad, &means.nodeLoad)
481481
log.KvDistribution.VInfof(ctx, 2, "considering lease-transfer r%v from s%v: candidates are %v", rangeID, store.StoreID, candsPL)
482482
if sls.dimSummary[CPURate] < overloadSlow {

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,14 @@ func (sls storeLoadSummary) SafeFormat(w redact.SafePrinter, _ rune) {
228228
// storeLoadSummary no longer matches that of storeState.loadSeqNum.
229229
type meansForStoreSet struct {
230230
constraintsDisj
231-
stores storeIDPostingList
231+
meansLoad
232+
stores storeIDPostingList
233+
storeSummaries map[roachpb.StoreID]storeLoadSummary
234+
}
235+
236+
type meansLoad struct {
232237
storeLoad meanStoreLoad
233238
nodeLoad meanNodeLoad
234-
235-
storeSummaries map[roachpb.StoreID]storeLoadSummary
236239
}
237240

238241
var _ mapEntry = &meansForStoreSet{}
@@ -339,7 +342,7 @@ func (mm *meansMemo) getMeans(expr constraintsDisj) *meansForStoreSet {
339342
}
340343
means.constraintsDisj = expr
341344
mm.constraintMatcher.constrainStoresForExpr(expr, &means.stores)
342-
computeMeansForStoreSet(mm.loadInfoProvider, means, mm.scratchNodes)
345+
computeMeansForStoreSet(mm.loadInfoProvider, &means.meansLoad, means.stores, mm.scratchNodes)
343346
return means
344347
}
345348

@@ -362,18 +365,30 @@ func (mm *meansMemo) getStoreLoadSummary(
362365
// It does not do any filtering e.g. the stores can include fdDead stores. It
363366
// is up to the caller to adjust means.stores if it wants to do filtering.
364367
//
368+
// stores may contain duplicate storeIDs, in which case computeMeansForStoreSet
369+
// should deduplicate processing of the stores. stores should be immutable.
370+
//
365371
// TODO: fix callers to exclude stores based on node failure detection, from
366372
// the mean.
367373
func computeMeansForStoreSet(
368-
loadProvider loadInfoProvider, means *meansForStoreSet, scratchNodes map[roachpb.NodeID]*NodeLoad,
374+
loadProvider loadInfoProvider,
375+
means *meansLoad,
376+
stores []roachpb.StoreID,
377+
scratchNodes map[roachpb.NodeID]*NodeLoad,
369378
) {
370-
n := len(means.stores)
371-
if n == 0 {
379+
if len(stores) == 0 {
372380
panic(fmt.Sprintf("no stores for meansForStoreSet: %v", *means))
373381
}
374382
clear(scratchNodes)
375-
for _, storeID := range means.stores {
383+
seen := make(map[roachpb.StoreID]struct{})
384+
n := 0
385+
for _, storeID := range stores {
376386
nodeID, sload := loadProvider.getStoreReportedLoad(storeID)
387+
if _, ok := seen[storeID]; ok {
388+
continue
389+
}
390+
n++
391+
seen[storeID] = struct{}{}
377392
for j := range sload.reportedLoad {
378393
means.storeLoad.load[j] += sload.reportedLoad[j]
379394
if sload.capacity[j] == UnknownCapacity {

0 commit comments

Comments
 (0)