Skip to content

Commit 5aef86c

Browse files
committed
kv: fix Replica stringer and SafeFormatter implementations
This commit fixes the Replica stringer and SafeFormatter implementations so that they correctly include the range descriptor string. This was unintentionally broken by 897d6e, which changed the return value of `atomicDescString.get`. Before this change, the stringer implementation looked something like: ``` [n1,s2,r&{3/4:{a-b} 3/4:{a-b} 3/4}] ``` The confusing `&{...}` portion was the internal structure `atomicDescInfo`. After, it looks like: ``` [n1,s2,r3/4:{a-b}] ``` Epic: None Release note: None
1 parent 8c1ff51 commit 5aef86c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pkg/kv/kvserver/replica.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ func (r *Replica) String() string {
922922
// SafeFormat implements the redact.SafeFormatter interface.
923923
func (r *Replica) SafeFormat(w redact.SafePrinter, _ rune) {
924924
w.Printf("[n%d,s%d,r%s]",
925-
r.store.Ident.NodeID, r.store.Ident.StoreID, r.rangeStr.get())
925+
r.store.Ident.NodeID, r.store.Ident.StoreID, &r.rangeStr)
926926
}
927927

928928
// ReplicaID returns the ID for the Replica. This value is fixed for the

pkg/kv/kvserver/replica_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import (
7272
"github.com/cockroachdb/cockroach/pkg/util/uuid"
7373
"github.com/cockroachdb/errors"
7474
"github.com/cockroachdb/logtags"
75+
"github.com/cockroachdb/redact"
7576
"github.com/kr/pretty"
7677
"github.com/stretchr/testify/assert"
7778
"github.com/stretchr/testify/require"
@@ -471,6 +472,29 @@ func TestIsOnePhaseCommit(t *testing.T) {
471472
}
472473
}
473474

475+
func TestReplicaStringAndSafeFormat(t *testing.T) {
476+
defer leaktest.AfterTest(t)()
477+
defer log.Scope(t).Close(t)
478+
479+
// This test really only needs a hollow shell of a Store and Replica.
480+
s := &Store{}
481+
s.Ident = &roachpb.StoreIdent{NodeID: 1, StoreID: 2}
482+
r := &Replica{}
483+
r.store = s
484+
r.rangeStr.store(4, &roachpb.RangeDescriptor{
485+
RangeID: 3,
486+
StartKey: roachpb.RKey("a"),
487+
EndKey: roachpb.RKey("b"),
488+
})
489+
490+
// String.
491+
assert.Equal(t, "[n1,s2,r3/4:{a-b}]", r.String())
492+
// Redactable string.
493+
assert.EqualValues(t, "[n1,s2,r3/4:‹{a-b}›]", redact.Sprint(r))
494+
// Redacted string.
495+
assert.EqualValues(t, "[n1,s2,r3/4:‹×›]", redact.Sprint(r).Redact())
496+
}
497+
474498
// TestReplicaContains verifies that the range uses Key.Address() in
475499
// order to properly resolve addresses for local keys.
476500
func TestReplicaContains(t *testing.T) {

0 commit comments

Comments
 (0)