Skip to content

Commit

Permalink
kv: plumb context into msgAppDropper.ShouldDrop
Browse files Browse the repository at this point in the history
Avoids the `context.Background` in `replicaMsgAppDropper.ShouldDrop`.
  • Loading branch information
nvanbenschoten committed Dec 22, 2021
1 parent 81f505e commit d3eb7c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions pkg/kv/kvserver/split_trigger_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ func (rd *replicaMsgAppDropper) Args() (initialized bool, ticks int) {
return initialized, ticks
}

func (rd *replicaMsgAppDropper) ShouldDrop(startKey roachpb.RKey) (fmt.Stringer, bool) {
func (rd *replicaMsgAppDropper) ShouldDrop(
ctx context.Context, startKey roachpb.RKey,
) (fmt.Stringer, bool) {
lhsRepl := (*Replica)(rd).store.LookupReplica(startKey)
if lhsRepl == nil {
return nil, false
}
lhsRepl.store.replicaGCQueue.AddAsync(context.Background(), lhsRepl, replicaGCPriorityDefault)
lhsRepl.store.replicaGCQueue.AddAsync(ctx, lhsRepl, replicaGCPriorityDefault)
return lhsRepl, true
}

type msgAppDropper interface {
Args() (initialized bool, ticks int)
ShouldDrop(key roachpb.RKey) (fmt.Stringer, bool)
ShouldDrop(ctx context.Context, key roachpb.RKey) (fmt.Stringer, bool)
}

// maybeDropMsgApp returns true if the incoming Raft message should be dropped.
Expand Down Expand Up @@ -130,7 +132,7 @@ func maybeDropMsgApp(

// NB: the caller is likely holding r.raftMu, but that's OK according to
// the lock order. We're not allowed to hold r.mu, but we don't.
lhsRepl, drop := r.ShouldDrop(startKey)
lhsRepl, drop := r.ShouldDrop(ctx, startKey)
if !drop {
return false
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/kv/kvserver/split_trigger_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func (td *testMsgAppDropper) Args() (initialized bool, ticks int) {
return td.initialized, td.ticks
}

func (td *testMsgAppDropper) ShouldDrop(startKey roachpb.RKey) (fmt.Stringer, bool) {
func (td *testMsgAppDropper) ShouldDrop(
ctx context.Context, startKey roachpb.RKey,
) (fmt.Stringer, bool) {
if len(startKey) == 0 {
panic("empty startKey")
}
Expand Down

0 comments on commit d3eb7c6

Please sign in to comment.