Skip to content

Commit

Permalink
metamorphic: allow KeyFormat to specify a KeySchema
Browse files Browse the repository at this point in the history
Allow KeyFormat to specify a KeySchema that should be used by the metamorphic
tests for columnar block sstables. This is in preparation for use of the
cockroachkvs package within the metamorphic test.

Informs #4167.
  • Loading branch information
jbowens committed Dec 31, 2024
1 parent 5076da5 commit c7e1b5a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions metamorphic/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ var keyFormatsByName = func() map[string]KeyFormat {
type KeyFormat struct {
Name string
Comparer *base.Comparer
KeySchema *pebble.KeySchema
FormatKey func(UserKey) string
FormatKeySuffix func(UserKeySuffix) string
ParseFormattedKey func(string) (UserKey, error)
Expand Down
2 changes: 1 addition & 1 deletion metamorphic/key_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (k *keyManager) getSetOfVisibleKeys(readerID objID) [][]byte {
keys = append(keys, unsafe.Slice(unsafe.StringData(k), len(k)))
}
}
slices.SortFunc(keys, testkeys.Comparer.Compare)
slices.SortFunc(keys, k.kf.Comparer.Compare)
return keys
}

Expand Down
12 changes: 7 additions & 5 deletions metamorphic/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/cockroachdb/pebble/bloom"
"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/cache"
"github.com/cockroachdb/pebble/internal/testkeys"
"github.com/cockroachdb/pebble/objstorage/remote"
"github.com/cockroachdb/pebble/sstable"
"github.com/cockroachdb/pebble/sstable/block"
Expand Down Expand Up @@ -296,21 +295,24 @@ func optionsToString(opts *TestOptions) string {
}

func defaultTestOptions() *TestOptions {
kf := TestkeysKeyFormat
return &TestOptions{
Opts: defaultOptions(),
Opts: defaultOptions(kf),
Threads: 16,
RetryPolicy: NeverRetry,
KeyFormat: TestkeysKeyFormat,
KeyFormat: kf,
}
}

func defaultOptions() *pebble.Options {
func defaultOptions(kf KeyFormat) *pebble.Options {
opts := &pebble.Options{
// Use an archive cleaner to ease post-mortem debugging.
Cleaner: base.ArchiveCleaner{},
// Always use our custom comparer which provides a Split method,
// splitting keys at the trailing '@'.
Comparer: testkeys.Comparer,
Comparer: kf.Comparer,
KeySchema: kf.KeySchema.Name,
KeySchemas: sstable.MakeKeySchemas(kf.KeySchema),
FS: vfs.NewMem(),
FormatMajorVersion: defaultFormatMajorVersion,
Levels: []pebble.LevelOptions{{
Expand Down
2 changes: 1 addition & 1 deletion metamorphic/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestSetupInitialState(t *testing.T) {
// setupInitialState with an initial state path set to the test's TempDir
// should populate opts.opts.FS with the directory's contents.
opts := &TestOptions{
Opts: defaultOptions(),
Opts: defaultOptions(TestkeysKeyFormat),
initialStatePath: initialStatePath,
initialStateDesc: "test",
}
Expand Down
7 changes: 6 additions & 1 deletion metamorphic/testkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ import (
"github.com/cockroachdb/pebble"
"github.com/cockroachdb/pebble/internal/testkeys"
"github.com/cockroachdb/pebble/sstable"
"github.com/cockroachdb/pebble/sstable/colblk"
)

var TestkeysKeyFormat = KeyFormat{
Comparer: testkeys.Comparer,
Comparer: testkeys.Comparer,
KeySchema: func() *colblk.KeySchema {
kf := colblk.DefaultKeySchema(testkeys.Comparer, 16 /* bundle size */)
return &kf
}(),
FormatKey: func(k UserKey) string { return string(k) },
FormatKeySuffix: func(s UserKeySuffix) string { return string(s) },
NewGenerator: func(km *keyManager, rng *rand.Rand, cfg OpConfig) KeyGenerator {
Expand Down

0 comments on commit c7e1b5a

Please sign in to comment.