Skip to content

Commit f6110ae

Browse files
committed
mmaprototype: pass context properly
This commit ensures `IsInConflictWithMMA` receives a proper context so that its logs appear in traces.
1 parent 263b219 commit f6110ae

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,7 @@ func (a Allocator) RebalanceTarget(
19111911
// would have been deleted from the candidates set in bestRebalanceTarget,
19121912
// so we will not select it again.
19131913
if advisor := results[bestIdx].advisor; advisor != nil {
1914-
if a.as.IsInConflictWithMMA(target.store.StoreID, advisor, false) {
1914+
if a.as.IsInConflictWithMMA(ctx, target.store.StoreID, advisor, false) {
19151915
continue
19161916
}
19171917
} else {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,19 +1343,18 @@ func (a *allocatorState) BuildMMARebalanceAdvisor(
13431343
// for making sure the MMARebalanceAdvisor is for the correct existing store and
13441344
// candidate set.
13451345
func (a *allocatorState) IsInConflictWithMMA(
1346-
cand roachpb.StoreID, advisor *MMARebalanceAdvisor, cpuOnly bool,
1346+
ctx context.Context, cand roachpb.StoreID, advisor *MMARebalanceAdvisor, cpuOnly bool,
13471347
) bool {
13481348
if advisor.disabled {
13491349
return false
13501350
}
13511351
if advisor.existingStoreSLS == nil {
1352-
// TODO(wenyihu6): pass in the actual ctx here
1353-
summary := a.cs.computeLoadSummary(context.Background(), advisor.existingStoreID,
1352+
summary := a.cs.computeLoadSummary(ctx, advisor.existingStoreID,
13541353
&advisor.means.storeLoad, &advisor.means.nodeLoad)
13551354
advisor.existingStoreSLS = &summary
13561355
}
13571356
existingSLS := advisor.existingStoreSLS
1358-
candSLS := a.cs.computeLoadSummary(context.Background(), cand, &advisor.means.storeLoad, &advisor.means.nodeLoad)
1357+
candSLS := a.cs.computeLoadSummary(ctx, cand, &advisor.means.storeLoad, &advisor.means.nodeLoad)
13591358
if cpuOnly {
13601359
return candSLS.dimSummary[CPURate] > existingSLS.dimSummary[CPURate]
13611360
}

pkg/kv/kvserver/mmaintegration/allocator_sync.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package mmaintegration
77

88
import (
9+
"context"
10+
911
"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
1012
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator"
1113
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/mmaprototype"
@@ -52,7 +54,7 @@ type mmaState interface {
5254
BuildMMARebalanceAdvisor(existing roachpb.StoreID, cands []roachpb.StoreID) *mmaprototype.MMARebalanceAdvisor
5355
// IsInConflictWithMMA is called by the allocator sync to determine if the
5456
// given candidate is in conflict with the existing store.
55-
IsInConflictWithMMA(cand roachpb.StoreID, advisor *mmaprototype.MMARebalanceAdvisor, cpuOnly bool) bool
57+
IsInConflictWithMMA(ctx context.Context, cand roachpb.StoreID, advisor *mmaprototype.MMARebalanceAdvisor, cpuOnly bool) bool
5658
}
5759

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

pkg/kv/kvserver/mmaintegration/thrashing.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package mmaintegration
77

88
import (
9+
"context"
10+
911
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/mmaprototype"
1012
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase"
1113
"github.com/cockroachdb/cockroach/pkg/roachpb"
@@ -101,10 +103,13 @@ func (as *AllocatorSync) BuildMMARebalanceAdvisor(
101103

102104
// IsInConflictWithMMA determines if a candidate conflicts with MMA's goals.
103105
func (as *AllocatorSync) IsInConflictWithMMA(
104-
cand roachpb.StoreID, advisor *mmaprototype.MMARebalanceAdvisor, cpuOnly bool,
106+
ctx context.Context,
107+
cand roachpb.StoreID,
108+
advisor *mmaprototype.MMARebalanceAdvisor,
109+
cpuOnly bool,
105110
) bool {
106111
if as.knobs != nil && as.knobs.OverrideIsInConflictWithMMA != nil {
107112
return as.knobs.OverrideIsInConflictWithMMA(cand)
108113
}
109-
return as.mmaAllocator.IsInConflictWithMMA(cand, advisor, cpuOnly)
114+
return as.mmaAllocator.IsInConflictWithMMA(ctx, cand, advisor, cpuOnly)
110115
}

0 commit comments

Comments
 (0)