From 61d7296c7ce3a707a5bc364c770d6979724ad27d Mon Sep 17 00:00:00 2001 From: Tobias Grieger Date: Thu, 19 Jan 2023 10:07:19 +0100 Subject: [PATCH] storage: add string repr for FullReplicaID Helpful for subsequent unit testing involving this type. NB: this type is in the wrong place. Now's not the time to move it. Epic: none Release note: None --- pkg/storage/BUILD.bazel | 1 + pkg/storage/replicas_storage.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/storage/BUILD.bazel b/pkg/storage/BUILD.bazel index d5a383a7ce68..d28813935a27 100644 --- a/pkg/storage/BUILD.bazel +++ b/pkg/storage/BUILD.bazel @@ -91,6 +91,7 @@ go_library( "@com_github_cockroachdb_pebble//vfs", "@com_github_cockroachdb_pebble//vfs/atomicfs", "@com_github_cockroachdb_redact//:redact", + "@com_github_cockroachdb_redact//interfaces", "@com_github_dustin_go_humanize//:go-humanize", "@com_github_elastic_gosigar//:gosigar", "@com_github_gogo_protobuf//proto", diff --git a/pkg/storage/replicas_storage.go b/pkg/storage/replicas_storage.go index 17953e84cafc..05d42e38fd4d 100644 --- a/pkg/storage/replicas_storage.go +++ b/pkg/storage/replicas_storage.go @@ -12,6 +12,8 @@ package storage import ( "github.com/cockroachdb/cockroach/pkg/roachpb" + "github.com/cockroachdb/redact" + "github.com/cockroachdb/redact/interfaces" "go.etcd.io/raft/v3/raftpb" ) @@ -540,6 +542,17 @@ type FullReplicaID struct { ReplicaID roachpb.ReplicaID } +// SafeFormat implements redact.SafeFormatter. It prints as +// r/. +func (id FullReplicaID) SafeFormat(s interfaces.SafePrinter, _ rune) { + s.Printf("r%d/%d", id.RangeID, id.ReplicaID) +} + +// String formats a store for debug output. +func (id FullReplicaID) String() string { + return redact.StringWithoutMarkers(id) +} + // ReplicaInfo provides the replica ID and state pair. type ReplicaInfo struct { FullReplicaID