Skip to content

Commit bd9f76e

Browse files
committed
print: print LockTableKey
Epic: none Release note: none
1 parent 48775d3 commit bd9f76e

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

pkg/kv/kvserver/print/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ go_test(
3030
srcs = ["debug_print_test.go"],
3131
embed = [":print"],
3232
deps = [
33+
"//pkg/kv/kvserver/concurrency/lock",
3334
"//pkg/kv/kvserver/kvserverpb",
3435
"//pkg/roachpb",
3536
"//pkg/storage",
@@ -38,6 +39,7 @@ go_test(
3839
"//pkg/util/hlc",
3940
"//pkg/util/leaktest",
4041
"//pkg/util/log",
42+
"//pkg/util/uuid",
4143
"@com_github_cockroachdb_pebble//:pebble",
4244
"@com_github_stretchr_testify//require",
4345
],

pkg/kv/kvserver/print/debug_print.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,12 @@ func SprintEngineKeyValue(k storage.EngineKey, v []byte) string {
9797
if key, err := k.ToMVCCKey(); err == nil {
9898
return SprintMVCCKeyValue(storage.MVCCKeyValue{Key: key, Value: v}, true /* printKey */)
9999
}
100+
} else if k.IsLockTableKey() {
101+
if key, err := k.ToLockTableKey(); err == nil {
102+
return fmt.Sprintf("%s: %s", key, SprintIntent(v))
103+
}
100104
}
101-
var sb strings.Builder
102-
fmt.Fprintf(&sb, "%s %x (%#x): ", k.Key, k.Version, k.Encode())
103-
if out, err := tryIntent(storage.MVCCKeyValue{Value: v}); err == nil {
104-
sb.WriteString(out)
105-
} else {
106-
fmt.Fprintf(&sb, "%x", v)
107-
}
108-
return sb.String()
105+
return fmt.Sprintf("%s %x (%#x): %x", k.Key, k.Version, k.Encode(), v)
109106
}
110107

111108
// SprintEngineRangeKeyValue is like PrintEngineRangeKeyValue, but returns a

pkg/kv/kvserver/print/debug_print_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"math"
1111
"testing"
1212

13+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock"
1314
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb"
1415
"github.com/cockroachdb/cockroach/pkg/roachpb"
1516
"github.com/cockroachdb/cockroach/pkg/storage"
@@ -18,6 +19,7 @@ import (
1819
"github.com/cockroachdb/cockroach/pkg/util/hlc"
1920
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
2021
"github.com/cockroachdb/cockroach/pkg/util/log"
22+
"github.com/cockroachdb/cockroach/pkg/util/uuid"
2123
"github.com/cockroachdb/pebble"
2224
"github.com/stretchr/testify/require"
2325
)
@@ -38,10 +40,19 @@ func TestStringifyWriteBatch(t *testing.T) {
3840
Key: roachpb.Key("/db1"),
3941
Timestamp: hlc.Timestamp{WallTime: math.MaxInt64},
4042
}), []byte("test value"), nil /* WriteOptions */))
43+
44+
ltKey, _ := storage.LockTableKey{
45+
Key: roachpb.Key("/key"), Strength: lock.Intent, TxnUUID: uuid.UUID{},
46+
}.ToEngineKey(nil)
47+
require.NoError(t, batch.Set(ltKey.Encode(), []byte("intent"), nil))
48+
4149
wb.Data = batch.Repr()
4250
s, err = DecodeWriteBatch(wb.Data)
4351
require.NoError(t, err)
44-
require.Equal(t, "Put: 9223372036.854775807,0 \"/db1\" (0x2f646231007fffffffffffffff09): \"test value\"\n", s)
52+
require.Equal(t,
53+
`Put: 9223372036.854775807,0 "/db1" (0x2f646231007fffffffffffffff09): "test value"
54+
Put: "/key"/Intent/00000000-0000-0000-0000-000000000000: 696e74656e74
55+
`, s)
4556

4657
batch = pebble.Batch{}
4758
encodedKey, err := hex.DecodeString("017a6b12c089f704918df70bee8800010003623a9318c0384d07a6f22b858594df6012")

pkg/storage/engine_key.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ type LockTableKey struct {
264264
TxnUUID uuid.UUID
265265
}
266266

267+
// Format implements the fmt.Formatter interface.
268+
func (lk LockTableKey) Format(f fmt.State, _ rune) {
269+
fmt.Fprintf(f, "%s/%s/%s", lk.Key, lk.Strength, lk.TxnUUID)
270+
}
271+
267272
// replicatedLockStrengthToByte is a mapping between lock.Strength and the
268273
// strength byte persisted in a lock table key's encoding. See
269274
// LockTableKey.ToEngineKey().

0 commit comments

Comments
 (0)