Skip to content

Commit

Permalink
storage: Include range IDs in stack traces
Browse files Browse the repository at this point in the history
Use dummy wrapper functions at key points (withRaftGroupLocked and
Replica.Send) to ensure that the range ID is visible in the stack
trace.

Fixes #11684

Release note: None
  • Loading branch information
bdarnell committed Jul 9, 2018
1 parent 888d8fc commit 20db4ad
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/storage/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,11 @@ func (r *Replica) withRaftGroupLocked(
}
}

unquiesce, err := f(r.mu.internalRaftGroup)
// This wrapper function is a hack to add range IDs to stack traces
// using the same pattern as Replica.sendWithRangeID.
unquiesce, err := func(rangeID roachpb.RangeID, raftGroup *raft.RawNode) (bool, error) {
return f(raftGroup)
}(r.RangeID, r.mu.internalRaftGroup)
if unquiesce {
r.unquiesceAndWakeLeaderLocked()
}
Expand Down Expand Up @@ -1911,6 +1915,23 @@ func (r *Replica) maybeInitializeRaftGroup(ctx context.Context) {
// ctx should contain the log tags from the store (and up).
func (r *Replica) Send(
ctx context.Context, ba roachpb.BatchRequest,
) (*roachpb.BatchResponse, *roachpb.Error) {
return r.sendWithRangeID(ctx, r.RangeID, ba)
}

// sendWithRangeID takes an unused rangeID argument so that the range
// ID will be accessible in stack traces (both in panics and when
// sampling goroutines from a live server). This line is subject to
// the whims of the compiler and it can be difficult to find the right
// value, but as of this writing the following example shows a stack
// while processing range 21 (0x15) (the first occurrence of that
// number is the rangeID argument, the second is within the encoded
// BatchRequest, although we don't want to rely on that occurring
// within the portion printed in the stack trace):
//
// github.com/cockroachdb/cockroach/pkg/storage.(*Replica).sendWithRangeID(0xc420d1a000, 0x64bfb80, 0xc421564b10, 0x15, 0x153fd4634aeb0193, 0x0, 0x100000001, 0x1, 0x15, 0x0, ...)
func (r *Replica) sendWithRangeID(
ctx context.Context, rangeID roachpb.RangeID, ba roachpb.BatchRequest,
) (*roachpb.BatchResponse, *roachpb.Error) {
var br *roachpb.BatchResponse
if r.leaseholderStats != nil && ba.Header.GatewayNodeID != 0 {
Expand Down

0 comments on commit 20db4ad

Please sign in to comment.