Skip to content

Commit

Permalink
cmd/pebble: populate common KeySchemas
Browse files Browse the repository at this point in the history
Update the cmd/pebble CLI tool to populate opts.KeySchemas with commonly used
KeySchemas. This was motivated by a desire to use the cmd/pebble CLI tool with
a sstable constructed by the metamorphic tests.
  • Loading branch information
jbowens committed Oct 24, 2024
1 parent faa0ea5 commit 4afb630
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/pebble/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/cockroachdb/pebble/internal/crdbtest"
"github.com/cockroachdb/pebble/internal/testkeys"
"github.com/cockroachdb/pebble/sstable/colblk"
"github.com/cockroachdb/pebble/tool"
"github.com/spf13/cobra"
)
Expand All @@ -31,6 +32,16 @@ var (
secondaryCacheSize int64
)

// Define the default testkeys key schema. Feeding this schema to the tool
// ensures the cmd/pebble cli tool natively understands the sstables constructed
// by our test cases.
//
// TODO(jackson): Ideally when a sstable.Reader finds a key schema that's a
// DefaultKeySchema not already in the KeySchemas constructed with a Comparer
// that it knows of, it would automatically construct the appropriate KeySchema.
// Or at least the cli tool should.
var testKeysSchema = colblk.DefaultKeySchema(testkeys.Comparer, 16)

func main() {
log.SetFlags(0)

Expand Down Expand Up @@ -58,7 +69,11 @@ func main() {
}
rootCmd.AddCommand(benchCmd)

t := tool.New(tool.Comparers(&crdbtest.Comparer, testkeys.Comparer), tool.Mergers(fauxMVCCMerger))
t := tool.New(
tool.Comparers(&crdbtest.Comparer, testkeys.Comparer),
tool.Mergers(fauxMVCCMerger),
tool.KeySchemas(&crdbtest.KeySchema, &testKeysSchema),
)
rootCmd.AddCommand(t.Commands...)

for _, cmd := range []*cobra.Command{replayCmd, scanCmd, syncCmd, tombstoneCmd, writeBenchCmd, ycsbCmd} {
Expand Down
3 changes: 3 additions & 0 deletions tool/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func Comparers(cmps ...*Comparer) Option {
// introspection tools.
func KeySchemas(schemas ...*colblk.KeySchema) Option {
return func(t *T) {
if t.opts.KeySchemas == nil {
t.opts.KeySchemas = make(map[string]*colblk.KeySchema)
}
for _, s := range schemas {
t.opts.KeySchemas[s.Name] = s
}
Expand Down

0 comments on commit 4afb630

Please sign in to comment.