diff --git a/pkg/kv/kvclient/kvcoord/dist_sender_test.go b/pkg/kv/kvclient/kvcoord/dist_sender_test.go index 98d4a9d890ae..0cee5a4e7dd3 100644 --- a/pkg/kv/kvclient/kvcoord/dist_sender_test.go +++ b/pkg/kv/kvclient/kvcoord/dist_sender_test.go @@ -32,6 +32,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv/kvclient/rangecache" "github.com/cockroachdb/cockroach/pkg/kv/kvpb" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/isolation" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock" "github.com/cockroachdb/cockroach/pkg/multitenant" "github.com/cockroachdb/cockroach/pkg/multitenant/tenantcostmodel" "github.com/cockroachdb/cockroach/pkg/roachpb" @@ -4530,12 +4531,14 @@ func TestDistSenderSlowLogMessage(t *testing.T) { ba := &kvpb.BatchRequest{} get := &kvpb.GetRequest{} get.Key = roachpb.Key("a") + get.KeyLockingStrength = lock.Shared + get.KeyLockingDurability = lock.Unreplicated ba.Add(get) br := &kvpb.BatchResponse{} br.Error = kvpb.NewError(errors.New("boom")) desc := &roachpb.RangeDescriptor{RangeID: 9, StartKey: roachpb.RKey("x"), EndKey: roachpb.RKey("z")} { - exp := `have been waiting 8.16s (120 attempts) for RPC Get [‹"a"›,/Min) to` + + exp := `have been waiting 8.16s (120 attempts) for RPC Get [‹"a"›,/Min)[lockStrength=Shared,lockDurability=Unreplicated] to` + ` r9:‹{x-z}› [, next=0, gen=0]; resp: ‹(err: boom)›` var s redact.StringBuilder slowRangeRPCWarningStr(&s, ba, dur, attempts, desc, nil /* err */, br) diff --git a/pkg/kv/kvpb/api.go b/pkg/kv/kvpb/api.go index 2fd1b9cf1060..9575b74e1be2 100644 --- a/pkg/kv/kvpb/api.go +++ b/pkg/kv/kvpb/api.go @@ -194,6 +194,42 @@ type Request interface { flags() flag } +// SafeFormatterRequest is an optional extension interface used to allow request to do custom formatting. +type SafeFormatterRequest interface { + Request + redact.SafeFormatter +} + +var _ SafeFormatterRequest = (*GetRequest)(nil) + +// SafeFormat implements the redact.SafeFormatter interface. +func (gr GetRequest) SafeFormat(s redact.SafePrinter, _ rune) { + if gr.KeyLockingStrength == lock.None { + return + } + s.Printf("[lockStrength=%s,lockDurability=%s]", gr.KeyLockingStrength, gr.KeyLockingDurability) +} + +var _ SafeFormatterRequest = (*ScanRequest)(nil) + +// SafeFormat implements the redact.SafeFormatter interface. +func (sr ScanRequest) SafeFormat(s redact.SafePrinter, _ rune) { + if sr.KeyLockingStrength == lock.None { + return + } + s.Printf("[lockStrength=%s,lockDurability=%s]", sr.KeyLockingStrength, sr.KeyLockingDurability) +} + +var _ SafeFormatterRequest = (*ReverseScanRequest)(nil) + +// SafeFormat implements the redact.SafeFormatter interface. +func (rsr ReverseScanRequest) SafeFormat(s redact.SafePrinter, _ rune) { + if rsr.KeyLockingStrength == lock.None { + return + } + s.Printf("[lockStrength=%s,lockDurability=%s]", rsr.KeyLockingStrength, rsr.KeyLockingDurability) +} + // LockingReadRequest is an interface used to expose the key-level locking // strength of a read-only request. type LockingReadRequest interface { diff --git a/pkg/kv/kvpb/batch.go b/pkg/kv/kvpb/batch.go index 4f57063274d6..1e7a08a7fb91 100644 --- a/pkg/kv/kvpb/batch.go +++ b/pkg/kv/kvpb/batch.go @@ -795,7 +795,7 @@ func (ba BatchRequest) Split(canSplitET bool) [][]RequestUnion { // SafeFormat implements redact.SafeFormatter. // It gives a brief summary of the contained requests and keys in the batch. -func (ba BatchRequest) SafeFormat(s redact.SafePrinter, _ rune) { +func (ba BatchRequest) SafeFormat(s redact.SafePrinter, verb rune) { for count, arg := range ba.Requests { // Limit the strings to provide just a summary. Without this limit // a log message with a BatchRequest can be very long. @@ -845,6 +845,9 @@ func (ba BatchRequest) SafeFormat(s redact.SafePrinter, _ rune) { s.Print(req.Method()) } s.Printf(" [%s,%s)", h.Key, h.EndKey) + if safeFormatterReq, ok := req.(SafeFormatterRequest); ok { + safeFormatterReq.SafeFormat(s, verb) + } } } {