diff --git a/open.go b/open.go index 2ab0b6cde1..eb4c0e3c48 100644 --- a/open.go +++ b/open.go @@ -1022,7 +1022,7 @@ func (d *DB) replayWAL( } d.opts.Logger.Infof("[JOB %d] WAL %s stopped reading at offset: %s; replayed %d keys in %d batches", - jobID, base.DiskFileNum(ll.Num).String(), offset, keysReplayed, batchesReplayed) + jobID, errors.Safe(ll.String()), offset, keysReplayed, batchesReplayed) if !d.opts.ReadOnly { flushMem() } diff --git a/wal/reader.go b/wal/reader.go index a08e7f60f6..80e11377b6 100644 --- a/wal/reader.go +++ b/wal/reader.go @@ -7,16 +7,15 @@ package wal import ( "bytes" "cmp" - "fmt" "io" "slices" - "strings" "github.com/cockroachdb/errors" "github.com/cockroachdb/pebble/batchrepr" "github.com/cockroachdb/pebble/internal/base" "github.com/cockroachdb/pebble/record" "github.com/cockroachdb/pebble/vfs" + "github.com/cockroachdb/redact" ) // A LogicalLog identifies a logical WAL and its consituent segment files. @@ -38,7 +37,12 @@ type segment struct { // String implements fmt.Stringer. func (s segment) String() string { - return fmt.Sprintf("(%s,%s)", s.dir.Dirname, s.logNameIndex) + return redact.StringWithoutMarkers(s) +} + +// SafeFormat implements redact.SafeFormatter. +func (s segment) SafeFormat(w redact.SafePrinter, _ rune) { + w.Printf("(%s,%s)", errors.Safe(s.dir.Dirname), s.logNameIndex) } // NumSegments returns the number of constituent physical log files that make up @@ -73,17 +77,19 @@ func (ll LogicalLog) OpenForRead() Reader { // String implements fmt.Stringer. func (ll LogicalLog) String() string { - var sb strings.Builder - sb.WriteString(base.DiskFileNum(ll.Num).String()) - sb.WriteString(": {") + return redact.StringWithoutMarkers(ll) +} + +// SafeFormat implements redact.SafeFormatter. +func (ll LogicalLog) SafeFormat(w redact.SafePrinter, _ rune) { + w.Printf("%s: {", base.DiskFileNum(ll.Num).String()) for i := range ll.segments { if i > 0 { - sb.WriteString(", ") + w.SafeString(", ") } - sb.WriteString(ll.segments[i].String()) + w.Print(ll.segments[i]) } - sb.WriteString("}") - return sb.String() + w.SafeString("}") } // appendDeletableLogs appends all of the LogicalLog's constituent physical diff --git a/wal/wal.go b/wal/wal.go index 6df38a7e67..d97bedd5b9 100644 --- a/wal/wal.go +++ b/wal/wal.go @@ -15,6 +15,7 @@ import ( "github.com/cockroachdb/pebble/internal/base" "github.com/cockroachdb/pebble/record" "github.com/cockroachdb/pebble/vfs" + "github.com/cockroachdb/redact" "github.com/prometheus/client_golang/prometheus" ) @@ -434,8 +435,15 @@ type Offset struct { // String implements fmt.Stringer, returning a string representation of the // offset. func (o Offset) String() string { + return redact.StringWithoutMarkers(o) +} + +// SafeFormat implements redact.SafeFormatter. +func (o Offset) SafeFormat(w redact.SafePrinter, _ rune) { if o.PreviousFilesBytes > 0 { - return fmt.Sprintf("(%s: %d), %d from previous files", o.PhysicalFile, o.Physical, o.PreviousFilesBytes) + w.Printf("(%s: %d), %d from previous files", o.PhysicalFile, o.Physical, o.PreviousFilesBytes) + return } - return fmt.Sprintf("(%s: %d)", o.PhysicalFile, o.Physical) + w.Printf("(%s: %d)", o.PhysicalFile, o.Physical) + }