Skip to content

Commit

Permalink
storage: add string repr for FullReplicaID
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tbg committed Feb 2, 2023
1 parent 8c216e1 commit 61d7296
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/storage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions pkg/storage/replicas_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -540,6 +542,17 @@ type FullReplicaID struct {
ReplicaID roachpb.ReplicaID
}

// SafeFormat implements redact.SafeFormatter. It prints as
// r<rangeID>/<replicaID>.
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
Expand Down

0 comments on commit 61d7296

Please sign in to comment.