Skip to content

Commit

Permalink
kv: include locking strength and durability in Get/Scan/RevScan SafeF…
Browse files Browse the repository at this point in the history
…ormat

fixes: #114475
Release note: None.
  • Loading branch information
Eric.Yang committed Nov 15, 2023
1 parent c114b1d commit 17a7d25
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
27 changes: 27 additions & 0 deletions pkg/kv/kvpb/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,33 @@ 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) {
s.Printf("[lockStrength=%s lockingDurability=%s]", gr.KeyLockingStrength, gr.KeyLockingDurability)
}

var _ SafeFormatterRequest = (*ScanRequest)(nil)

// SafeFormat implements the redact.SafeFormatter interface.
func (sr ScanRequest) SafeFormat(s redact.SafePrinter, _ rune) {
s.Printf("[lockStrength=%s lockingDurability=%s]", sr.KeyLockingStrength, sr.KeyLockingDurability)
}

var _ SafeFormatterRequest = (*ReverseScanRequest)(nil)

// SafeFormat implements the redact.SafeFormatter interface.
func (rsr ReverseScanRequest) SafeFormat(s redact.SafePrinter, _ rune) {
s.Printf("[lockStrength=%s lockingDurability=%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 {
Expand Down
5 changes: 4 additions & 1 deletion pkg/kv/kvpb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}
}
{
Expand Down

0 comments on commit 17a7d25

Please sign in to comment.