Skip to content

Commit 21b12ba

Browse files
committed
tool: print encoding during manifest dump with verbose flag
Adjust the pebble introspection tool for dumping a manifest file to include the raw encoding of the version edit when the verbose flag is provided. This will be helpful in cases such as cockroachlabs/support#3249.
1 parent 16e16a9 commit 21b12ba

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

tool/manifest.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package tool
66

77
import (
8+
"bytes"
89
"cmp"
910
"fmt"
1011
"io"
@@ -14,6 +15,7 @@ import (
1415
"github.com/HdrHistogram/hdrhistogram-go"
1516
"github.com/cockroachdb/pebble"
1617
"github.com/cockroachdb/pebble/internal/base"
18+
"github.com/cockroachdb/pebble/internal/binfmt"
1719
"github.com/cockroachdb/pebble/internal/humanize"
1820
"github.com/cockroachdb/pebble/internal/manifest"
1921
"github.com/cockroachdb/pebble/record"
@@ -161,6 +163,17 @@ func (m *manifestT) runDump(cmd *cobra.Command, args []string) {
161163
fmt.Fprintf(stdout, "%s\n", err)
162164
break
163165
}
166+
fmt.Fprintf(stdout, "%d/%d\n", offset, editIdx)
167+
// If verbose, dump the binary encoding of the version edit.
168+
if m.verbose {
169+
data, err := io.ReadAll(r)
170+
if err != nil {
171+
fmt.Fprintf(stdout, "%s\n", err)
172+
break
173+
}
174+
r = bytes.NewReader(data)
175+
binfmt.FHexDump(stdout, data, 16, true)
176+
}
164177

165178
var ve manifest.VersionEdit
166179
err = ve.Decode(r)
@@ -178,7 +191,6 @@ func (m *manifestT) runDump(cmd *cobra.Command, args []string) {
178191
}
179192

180193
empty := true
181-
fmt.Fprintf(stdout, "%d/%d\n", offset, editIdx)
182194
if ve.ComparerName != "" {
183195
empty = false
184196
fmt.Fprintf(stdout, " comparer: %s", ve.ComparerName)

tool/testdata/manifest_dump

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,35 @@ EOF
4545
--- L5 ---
4646
--- L6 ---
4747

48+
manifest dump --verbose
49+
../testdata/db-stage-4/MANIFEST-000006
50+
----
51+
MANIFEST-000006
52+
0/0
53+
00: 011a6c65 76656c64 622e4279 74657769 | ..le veld b.By tewi
54+
10: 7365436f 6d706172 61746f72 02020307 | seCo mpar ator ....
55+
20: 0400 | ..
56+
comparer: leveldb.BytewiseComparator
57+
log-num: 2
58+
next-file-num: 7
59+
41/1
60+
00: 02050306 040e6700 04c5050b 62617200 | .... ..g. .... bar.
61+
10: 0e000000 0000000b 666f6f01 0d000000 | .... .... foo. ....
62+
20: 0000000c 0e060585 a6b8ab06 01 | .... .... .... .
63+
log-num: 5
64+
next-file-num: 6
65+
last-seq-num: 14
66+
added: L0 000004:709<#12-#14>[bar#14,DEL-foo#13,SET] (2023-12-04T17:57:25Z)
67+
EOF
68+
--- L0.0 ---
69+
000004:709<#12-#14>[bar#14,DEL-foo#13,SET]
70+
--- L1 ---
71+
--- L2 ---
72+
--- L3 ---
73+
--- L4 ---
74+
--- L5 ---
75+
--- L6 ---
76+
4877
manifest dump --filter-start=zoo
4978
../testdata/db-stage-4/MANIFEST-000006
5079
----
@@ -53,6 +82,7 @@ MANIFEST-000006
5382
comparer: leveldb.BytewiseComparator
5483
log-num: 2
5584
next-file-num: 7
85+
41/1
5686
EOF
5787
--- L0.0 ---
5888
--- L1 ---
@@ -70,6 +100,7 @@ MANIFEST-000006
70100
comparer: leveldb.BytewiseComparator
71101
log-num: 2
72102
next-file-num: 7
103+
41/1
73104
EOF
74105
--- L0.0 ---
75106
--- L1 ---
@@ -321,6 +352,7 @@ MANIFEST-000001
321352
0/0
322353
comparer: alt-comparer
323354
next-file-num: 2
355+
25/1
324356
38/1
325357
log-num: 4
326358
next-file-num: 6
@@ -335,6 +367,7 @@ MANIFEST-000001
335367
next-file-num: 7
336368
last-seq-num: 15
337369
added: L0 000006:680<#15-#15>[bbb#15,SET-ccc#15,SET] (2023-12-12T18:55:00Z)
370+
193/4
338371
243/4
339372
next-file-num: 9
340373
last-seq-num: 16

0 commit comments

Comments
 (0)