Skip to content

Commit 9750e37

Browse files
cache: mark cache panic messages as redact.Safe
Previously, panic messages in the cache package containing ref counts were being redacted when surfaced in CockroachDB logs, making it impossible to diagnose cache value ref counting issues. Wrap the panic format strings with redact.Safe() so the full message (including the ref count) is visible in redacted logs. Informs: cockroachdb/cockroach#164740. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
1 parent f719dfd commit 9750e37

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

internal/cache/cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/cockroachdb/pebble/internal/base"
1919
"github.com/cockroachdb/pebble/internal/invariants"
2020
"github.com/cockroachdb/pebble/internal/metricsutil"
21+
"github.com/cockroachdb/redact"
2122
)
2223

2324
// Cache implements Pebble's sharded block cache. The Clock-PRO algorithm is
@@ -327,7 +328,7 @@ func (c *Handle) GetWithReadHandle(
327328
// REQUIRES: value.refs() == 1
328329
func (c *Handle) Set(fileNum base.DiskFileNum, offset uint64, value *Value) {
329330
if n := value.refs(); n != 1 {
330-
panic(fmt.Sprintf("pebble: Value has already been added to the cache: refs=%d", n))
331+
panic(redact.Safe(fmt.Sprintf("pebble: Value has already been added to the cache: refs=%d", n)))
331332
}
332333
k := makeKey(c.id, fileNum, offset)
333334
c.cache.getShard(k).set(k, value, false /*markAccessed*/)

internal/cache/read_shard.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/cockroachdb/pebble/internal/invariants"
14+
"github.com/cockroachdb/redact"
1415
"github.com/cockroachdb/swiss"
1516
)
1617

@@ -295,7 +296,7 @@ func (e *readEntry) unrefAndTryRemoveFromMap() {
295296

296297
func (e *readEntry) setReadValue(v *Value) {
297298
if n := v.refs(); n != 1 {
298-
panic(fmt.Sprintf("pebble: Value has already been added to the cache: refs=%d", n))
299+
panic(redact.Safe(fmt.Sprintf("pebble: Value has already been added to the cache: refs=%d", n)))
299300
}
300301
concurrentRequesters := false
301302
e.mu.Lock()

internal/cache/value.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/cockroachdb/pebble/internal/buildtags"
1414
"github.com/cockroachdb/pebble/internal/invariants"
1515
"github.com/cockroachdb/pebble/internal/manual"
16+
"github.com/cockroachdb/redact"
1617
)
1718

1819
// ValueMetadataSize denotes the number of bytes of metadata allocated for a
@@ -143,7 +144,7 @@ func (v *Value) Release() {
143144
// Free. Do not call Free on a value that has been added to the cache.
144145
func Free(v *Value) {
145146
if n := v.refs(); n > 1 {
146-
panic(fmt.Sprintf("pebble: Value has been added to the cache: refs=%d", n))
147+
panic(redact.Safe(fmt.Sprintf("pebble: Value has been added to the cache: refs=%d", n)))
147148
}
148149
v.Release()
149150
}

0 commit comments

Comments
 (0)