Skip to content

Commit 0e1a672

Browse files
cache: mark cache panic messages as safe from redaction
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 errors.AssertionFailedf() 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 6e3f2e1 commit 0e1a672

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

internal/cache/cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"sync/atomic"
1616
"time"
1717

18+
"github.com/cockroachdb/errors"
1819
"github.com/cockroachdb/pebble/internal/base"
1920
"github.com/cockroachdb/pebble/internal/invariants"
2021
"github.com/cockroachdb/pebble/internal/metricsutil"
@@ -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(errors.AssertionFailedf("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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ package cache
66

77
import (
88
"context"
9-
"fmt"
109
"sync"
1110
"time"
1211

12+
"github.com/cockroachdb/errors"
1313
"github.com/cockroachdb/pebble/internal/invariants"
1414
"github.com/cockroachdb/swiss"
1515
)
@@ -295,7 +295,7 @@ func (e *readEntry) unrefAndTryRemoveFromMap() {
295295

296296
func (e *readEntry) setReadValue(v *Value) {
297297
if n := v.refs(); n != 1 {
298-
panic(fmt.Sprintf("pebble: Value has already been added to the cache: refs=%d", n))
298+
panic(errors.AssertionFailedf("pebble: Value has already been added to the cache: refs=%d", n))
299299
}
300300
concurrentRequesters := false
301301
e.mu.Lock()

internal/cache/value.go

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

13+
"github.com/cockroachdb/errors"
1314
"github.com/cockroachdb/pebble/internal/buildtags"
1415
"github.com/cockroachdb/pebble/internal/invariants"
1516
"github.com/cockroachdb/pebble/internal/manual"
@@ -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(errors.AssertionFailedf("pebble: Value has been added to the cache: refs=%d", n))
147148
}
148149
v.Release()
149150
}

0 commit comments

Comments
 (0)