Skip to content

Commit 132d6b6

Browse files
committed
tool: add db inspect manifest subcommand
Add a subcommand that finds the active manifest's filename (according to the atomic marker) and returns it. This can be composed with the `manifest` subcommands to examine the current manifest without manually finding the manifest files and determining which is current. Informs #5353.
1 parent 3df9a2f commit 132d6b6

File tree

2 files changed

+72
-15
lines changed

2 files changed

+72
-15
lines changed

tool/db.go

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,22 @@ import (
3333
// dbT implements db-level tools, including both configuration state and the
3434
// commands themselves.
3535
type dbT struct {
36-
Root *cobra.Command
37-
Check *cobra.Command
38-
Upgrade *cobra.Command
39-
Checkpoint *cobra.Command
40-
Get *cobra.Command
41-
Logs *cobra.Command
42-
LSM *cobra.Command
43-
Properties *cobra.Command
44-
Scan *cobra.Command
45-
Set *cobra.Command
46-
Space *cobra.Command
47-
IOBench *cobra.Command
48-
Excise *cobra.Command
49-
AnalyzeData *cobra.Command
36+
Root *cobra.Command
37+
Check *cobra.Command
38+
Upgrade *cobra.Command
39+
Checkpoint *cobra.Command
40+
Get *cobra.Command
41+
Inspect *cobra.Command
42+
InspectManifest *cobra.Command
43+
Logs *cobra.Command
44+
LSM *cobra.Command
45+
Properties *cobra.Command
46+
Scan *cobra.Command
47+
Set *cobra.Command
48+
Space *cobra.Command
49+
IOBench *cobra.Command
50+
Excise *cobra.Command
51+
AnalyzeData *cobra.Command
5052

5153
// Configuration.
5254
opts *pebble.Options
@@ -153,6 +155,13 @@ process.
153155
Args: cobra.ExactArgs(2),
154156
Run: d.runGet,
155157
}
158+
d.Inspect = &cobra.Command{
159+
Use: "inspect <dir>",
160+
Short: "inspect DB internals without opening",
161+
Long: `
162+
Inspect the DB internals without opening the DB.
163+
`,
164+
}
156165
d.Logs = logs.NewCmd()
157166
d.LSM = &cobra.Command{
158167
Use: "lsm <dir>",
@@ -235,7 +244,17 @@ experiments and produce a CSV file of the results.
235244
Run: d.runAnalyzeData,
236245
}
237246

238-
d.Root.AddCommand(d.Check, d.Upgrade, d.Checkpoint, d.Get, d.Logs, d.LSM, d.Properties, d.Scan, d.Set, d.Space, d.Excise, d.IOBench, d.AnalyzeData)
247+
d.Inspect.AddCommand(&cobra.Command{
248+
Use: "manifest <dir>",
249+
Short: "Return the manifest filename",
250+
Long: `
251+
Returns the filename of the current manifest file.
252+
`,
253+
Args: cobra.ExactArgs(1),
254+
Run: d.inspectManifest,
255+
})
256+
257+
d.Root.AddCommand(d.Check, d.Upgrade, d.Checkpoint, d.Get, d.Inspect, d.Logs, d.LSM, d.Properties, d.Scan, d.Set, d.Space, d.Excise, d.IOBench, d.AnalyzeData)
239258
d.Root.PersistentFlags().BoolVarP(&d.verbose, "verbose", "v", false, "verbose output")
240259

241260
for _, cmd := range []*cobra.Command{d.Check, d.Upgrade, d.Checkpoint, d.Get, d.LSM, d.Properties, d.Scan, d.Set, d.Space, d.Excise, d.AnalyzeData} {
@@ -431,6 +450,15 @@ func (d *dbT) closeDB(stderr io.Writer, db *pebble.DB) {
431450
}
432451
}
433452

453+
func (d *dbT) inspectManifest(cmd *cobra.Command, args []string) {
454+
desc, err := pebble.Peek(args[0], d.opts.FS)
455+
if err != nil {
456+
fmt.Fprintf(cmd.ErrOrStderr(), "%s\n", err)
457+
return
458+
}
459+
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", desc.ManifestFilename)
460+
}
461+
434462
func (d *dbT) runCheck(cmd *cobra.Command, args []string) {
435463
stdout, stderr := cmd.OutOrStdout(), cmd.ErrOrStderr()
436464
db, err := d.openDB(args[0])

tool/testdata/db_inspect

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
db inspect
2+
----
3+
----
4+
5+
Inspect the DB internals without opening the DB.
6+
7+
Usage:
8+
db inspect [command]
9+
10+
Available Commands:
11+
manifest Return the manifest filename
12+
13+
Flags:
14+
-h, --help help for inspect
15+
16+
Global Flags:
17+
-v, --verbose verbose output
18+
19+
Use " db inspect [command] --help" for more information about a command.
20+
----
21+
----
22+
23+
db inspect manifest
24+
----
25+
accepts 1 arg(s), received 0
26+
27+
db inspect manifest ../testdata/db-stage-4
28+
----
29+
db-stage-4/MANIFEST-000006

0 commit comments

Comments
 (0)