Skip to content

Commit

Permalink
Merge pull request #17778 from petermattis/pmattis/pretty-print-range…
Browse files Browse the repository at this point in the history
…-local-key

keys: fix pretty-printing of range local keys
  • Loading branch information
petermattis authored Aug 21, 2017
2 parents 798df64 + 2b35e26 commit a1440da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
23 changes: 17 additions & 6 deletions pkg/keys/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,22 +362,33 @@ func localRangeKeyPrint(key roachpb.Key) string {
if s.atEnd {
if bytes.HasSuffix(key, s.suffix) {
key = key[:len(key)-len(s.suffix)]
fmt.Fprintf(&buf, "%s/%s", decodeKeyPrint(key), s.name)
_, decodedKey, err := encoding.DecodeBytesAscending([]byte(key), nil)
if err != nil {
fmt.Fprintf(&buf, "%s/%s", decodeKeyPrint(key), s.name)
} else {
fmt.Fprintf(&buf, "%s/%s", roachpb.Key(decodedKey), s.name)
}
return buf.String()
}
} else {
begin := bytes.Index(key, s.suffix)
if begin > 0 {
addrKey := key[:begin]
_, decodedAddrKey, err := encoding.DecodeBytesAscending([]byte(addrKey), nil)
if err != nil {
fmt.Fprintf(&buf, "%s/%s", decodeKeyPrint(addrKey), s.name)
} else {
fmt.Fprintf(&buf, "%s/%s", roachpb.Key(decodedAddrKey), s.name)
}
if bytes.Equal(s.suffix, LocalTransactionSuffix) {
txnID, err := uuid.FromBytes(key[(begin + len(s.suffix)):])
if err != nil {
return fmt.Sprintf("/%q/err:%v", key, err)
}
fmt.Fprintf(&buf, "%s/%s/addrKey:/id:%q", decodeKeyPrint(addrKey), s.name, txnID)
fmt.Fprintf(&buf, "/%q", txnID)
} else {
id := key[(begin + len(s.suffix)):]
fmt.Fprintf(&buf, "%s/%s/addrKey:/id:%q", decodeKeyPrint(addrKey), s.name, id)
fmt.Fprintf(&buf, "/%q", []byte(id))
}
return buf.String()
}
Expand Down Expand Up @@ -519,9 +530,9 @@ func prettyPrintInternal(key roachpb.Key, quoteRawKeys bool) string {
// /[rangeid]/RangeLastVerificationTimestamp "\x01s"+[rangeid]+"rlvt"
// /[rangeid]/RangeStats "\x01s"+[rangeid]+"stat"
// /Range/... "\x01k"+...
// /RangeDescriptor/[key] "\x01k"+[key]+"rdsc"
// /Transaction/addrKey:[key]/id:[id] "\x01k"+[key]+"txn-"+[txn-id]
// /QueueLastProcessed/addrKey:[key]/id:[queue] "\x01k"+[key]+"qlpt"+[queue]
// [key]/RangeDescriptor "\x01k"+[key]+"rdsc"
// [key]/Transaction/[id] "\x01k"+[key]+"txn-"+[txn-id]
// [key]/QueueLastProcessed/[queue] "\x01k"+[key]+"qlpt"+[queue]
// /Local/Max "\x02"
//
// /Meta1/[key] "\x02"+[key]
Expand Down
7 changes: 3 additions & 4 deletions pkg/keys/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
)

func TestPrettyPrint(t *testing.T) {

tm, _ := time.Parse(time.RFC3339Nano, "2016-03-30T13:40:35.053725008Z")
duration := duration.Duration{Months: 1, Days: 1, Nanos: 1 * time.Second.Nanoseconds()}
durationAsc, _ := encoding.EncodeDurationAscending(nil, duration)
Expand Down Expand Up @@ -68,9 +67,9 @@ func TestPrettyPrint(t *testing.T) {
{RangeLastVerificationTimestampKeyDeprecated(roachpb.RangeID(1000001)), "/Local/RangeID/1000001/u/RangeLastVerificationTimestamp"},

{MakeRangeKeyPrefix(roachpb.RKey("ok")), `/Local/Range/"ok"`},
{RangeDescriptorKey(roachpb.RKey("111")), `/Local/Range/"111"/RangeDescriptor`},
{TransactionKey(roachpb.Key("111"), txnID), fmt.Sprintf(`/Local/Range/"111"/Transaction/addrKey:/id:%q`, txnID)},
{QueueLastProcessedKey(roachpb.RKey("111"), "foo"), `/Local/Range/"111"/QueueLastProcessed/addrKey:/id:"foo"`},
{RangeDescriptorKey(roachpb.RKey(MakeTablePrefix(42))), `/Local/Range/Table/42/RangeDescriptor`},
{TransactionKey(roachpb.Key(MakeTablePrefix(42)), txnID), fmt.Sprintf(`/Local/Range/Table/42/Transaction/%q`, txnID)},
{QueueLastProcessedKey(roachpb.RKey(MakeTablePrefix(42)), "foo"), `/Local/Range/Table/42/QueueLastProcessed/"foo"`},

{LocalMax, `/Meta1/""`}, // LocalMax == Meta1Prefix

Expand Down

0 comments on commit a1440da

Please sign in to comment.