Skip to content

Commit 15bea86

Browse files
committed
keys: pretty print WAG node keys
Epic: none Release note: none
1 parent 67d9183 commit 15bea86

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

pkg/keys/keys.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ func StoreWAGNodeKey(index uint64) roachpb.Key {
150150
return MakeStoreKey(localStoreWAGNodeSuffix, encoding.EncodeUint64Ascending(nil, index))
151151
}
152152

153+
// DecodeWAGNodeKey returns the index of the WAG node from its key.
154+
func DecodeWAGNodeKey(key roachpb.Key) (uint64, error) {
155+
suffix, detail, err := DecodeStoreKey(key)
156+
if err != nil {
157+
return 0, err
158+
}
159+
if !suffix.Equal(localStoreWAGNodeSuffix) {
160+
return 0, errors.Errorf("key with suffix %q != %q", suffix, localStoreWAGNodeSuffix)
161+
}
162+
detail, index, err := encoding.DecodeUint64Ascending(detail)
163+
if len(detail) != 0 {
164+
return 0, errors.Errorf("invalid key has trailing garbage: %q", detail)
165+
}
166+
return index, err
167+
}
168+
153169
// StoreCachedSettingsKey returns a store-local key for store's cached settings.
154170
func StoreCachedSettingsKey(settingKey roachpb.Key) roachpb.Key {
155171
return MakeStoreKey(localStoreCachedSettingsSuffix, encoding.EncodeBytesAscending(nil, settingKey))

pkg/keys/printer.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ var constSubKeyDict = []struct {
146146
{"/clusterVersion", localStoreClusterVersionSuffix},
147147
{"/nodeTombstone", localStoreNodeTombstoneSuffix},
148148
{"/cachedSettings", localStoreCachedSettingsSuffix},
149+
{"/wag", localStoreWAGNodeSuffix},
149150
{"/lossOfQuorumRecovery/applied", localStoreUnsafeReplicaRecoverySuffix},
150151
{"/lossOfQuorumRecovery/status", localStoreLossOfQuorumRecoveryStatusSuffix},
151152
{"/lossOfQuorumRecovery/cleanup", localStoreLossOfQuorumRecoveryCleanupActionsSuffix},
@@ -167,10 +168,19 @@ func cachedSettingsKeyPrint(buf *redact.StringBuilder, key roachpb.Key) {
167168
buf.Print(settingKey.String())
168169
}
169170

171+
func wagNodeKeyPrint(buf *redact.StringBuilder, key roachpb.Key) {
172+
index, err := DecodeWAGNodeKey(key)
173+
if err != nil {
174+
buf.Printf("<invalid: %s>", err)
175+
}
176+
buf.Printf("%d", index)
177+
}
178+
170179
func localStoreKeyPrint(buf *redact.StringBuilder, _ []encoding.Direction, key roachpb.Key) {
171180
for _, v := range constSubKeyDict {
172181
if bytes.HasPrefix(key, v.key) {
173182
buf.Print(v.name)
183+
// TODO(pav-kv): make this switch more efficient with a lookup.
174184
if v.key.Equal(localStoreNodeTombstoneSuffix) {
175185
buf.SafeRune('/')
176186
nodeTombstoneKeyPrint(
@@ -186,6 +196,9 @@ func localStoreKeyPrint(buf *redact.StringBuilder, _ []encoding.Direction, key r
186196
lossOfQuorumRecoveryEntryKeyPrint(
187197
buf, append(roachpb.Key(nil), append(LocalStorePrefix, key...)...),
188198
)
199+
} else if v.key.Equal(localStoreWAGNodeSuffix) {
200+
buf.SafeRune('/')
201+
wagNodeKeyPrint(buf, append(append(roachpb.Key(nil), LocalStorePrefix...), key...))
189202
}
190203
return
191204
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
echo
22
----
33
>> create
4-
Put: 0,0 /Local/Store"wagn\x00\x00\x00\x00\x00\x00\x00\x01" (0x01737761676e000000000000000100): "\n\x04\b{\x10\x04\x10\x01\x1a(\n&\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x12state-machine-key\x00\x05state"
4+
Put: 0,0 /Local/Store/wag/1 (0x01737761676e000000000000000100): "\n\x04\b{\x10\x04\x10\x01\x1a(\n&\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x12state-machine-key\x00\x05state"
55
>> init
6-
Put: 0,0 /Local/Store"wagn\x00\x00\x00\x00\x00\x00\x00\x02" (0x01737761676e000000000000000200): "\n\x06\b{\x10\x04 \n\x10\x02\x1a\x18\x12\x16\n\ttmp/1.sst\n\ttmp/2.sst"
6+
Put: 0,0 /Local/Store/wag/2 (0x01737761676e000000000000000200): "\n\x06\b{\x10\x04 \n\x10\x02\x1a\x18\x12\x16\n\ttmp/1.sst\n\ttmp/2.sst"
77
>> split
8-
Put: 0,0 /Local/Store"wagn\x00\x00\x00\x00\x00\x00\x00\x03" (0x01737761676e000000000000000300): "\n\a\b{\x10\x04 \xc7\x01\x10\x03\x1a\x00"
9-
Put: 0,0 /Local/Store"wagn\x00\x00\x00\x00\x00\x00\x00\x04" (0x01737761676e000000000000000400): "\n\a\b{\x10\x04 \xc8\x01\x10\x04\x1a6\n4\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\blhs-key\x00\tlhs-state\x01\brhs-key\x00\trhs-state \xb7\x04"
8+
Put: 0,0 /Local/Store/wag/3 (0x01737761676e000000000000000300): "\n\a\b{\x10\x04 \xc7\x01\x10\x03\x1a\x00"
9+
Put: 0,0 /Local/Store/wag/4 (0x01737761676e000000000000000400): "\n\a\b{\x10\x04 \xc8\x01\x10\x04\x1a6\n4\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\blhs-key\x00\tlhs-state\x01\brhs-key\x00\trhs-state \xb7\x04"

0 commit comments

Comments
 (0)