Skip to content

Commit 34f641b

Browse files
committed
db: clean up runDBDefineCmd
Consolidate the two variants of this function: we create a new `MemFS` only if `opts.FS` is not set (which is much more intuitive). Note that we no longer call `EnsureDefaults()` before modifying the options passed to the `define` directive. This changes certain values that have defaults that depends on other values, like `FlushSplitBytes`. We add a `flush-split-byte` argument to correct this.
1 parent 00352d0 commit 34f641b

File tree

8 files changed

+60
-45
lines changed

8 files changed

+60
-45
lines changed

compaction_picker_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,12 @@ type pausableCleaner struct {
14371437
cleaner Cleaner
14381438
}
14391439

1440+
func newPausableCleaner(cleaner Cleaner) *pausableCleaner {
1441+
p := &pausableCleaner{cleaner: cleaner}
1442+
p.cond.L = &p.mu
1443+
return p
1444+
}
1445+
14401446
func (c *pausableCleaner) Clean(fs vfs.FS, fileType base.FileType, path string) error {
14411447
c.mu.Lock()
14421448
defer c.mu.Unlock()
@@ -1460,9 +1466,7 @@ func (c *pausableCleaner) resume() {
14601466
}
14611467

14621468
func TestCompactionPickerScores(t *testing.T) {
1463-
fs := vfs.NewMem()
1464-
cleaner := pausableCleaner{cleaner: DeleteCleaner{}}
1465-
cleaner.cond.L = &cleaner.mu
1469+
cleaner := newPausableCleaner(DeleteCleaner{})
14661470

14671471
var d *DB
14681472
defer func() {
@@ -1497,11 +1501,10 @@ func TestCompactionPickerScores(t *testing.T) {
14971501
cleaner.pause()
14981502
}
14991503
opts := &Options{
1500-
Cleaner: &cleaner,
1504+
Cleaner: cleaner,
15011505
Comparer: testkeys.Comparer,
15021506
DisableAutomaticCompactions: true,
15031507
FormatMajorVersion: FormatNewest,
1504-
FS: fs,
15051508
Logger: testutils.Logger{T: t},
15061509
}
15071510
opts.Experimental.CompactionScheduler = func() CompactionScheduler {

compaction_test.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,31 +1452,38 @@ func TestCompaction(t *testing.T) {
14521452
"file_boundaries_delsized": {
14531453
minVersion: FormatDeleteSizedAndObsolete,
14541454
maxVersion: FormatFlushableIngestExcises,
1455+
cmp: DefaultComparer,
14551456
},
14561457
"set_with_del_sstable_Pebblev4": {
14571458
minVersion: FormatDeleteSizedAndObsolete,
14581459
maxVersion: FormatFlushableIngestExcises,
1460+
cmp: DefaultComparer,
14591461
},
14601462
"multilevel": {
14611463
minVersion: FormatMinSupported,
14621464
maxVersion: internalFormatNewest,
1465+
cmp: DefaultComparer,
14631466
},
14641467
"set_with_del_sstable_Pebblev5": {
14651468
minVersion: FormatColumnarBlocks,
14661469
maxVersion: FormatColumnarBlocks,
1470+
cmp: DefaultComparer,
14671471
},
14681472
"set_with_del_sstable_Pebblev6": {
14691473
minVersion: FormatTableFormatV6,
14701474
maxVersion: FormatTableFormatV6,
1475+
cmp: DefaultComparer,
14711476
},
14721477
"set_with_del_sstable_Pebblev7": {
14731478
minVersion: formatFooterAttributes,
14741479
maxVersion: formatFooterAttributes,
1480+
cmp: DefaultComparer,
14751481
},
14761482
"value_separation": {
14771483
minVersion: FormatValueSeparation,
14781484
maxVersion: FormatValueSeparation,
14791485
verbose: true,
1486+
cmp: DefaultComparer,
14801487
},
14811488
"mvcc_garbage_blob": {
14821489
minVersion: FormatValueSeparation,
@@ -1489,21 +1496,25 @@ func TestCompaction(t *testing.T) {
14891496
// since the test prints the compaction log which includes file sizes.
14901497
minVersion: formatDeprecatedExperimentalValueSeparation,
14911498
maxVersion: formatDeprecatedExperimentalValueSeparation,
1499+
cmp: DefaultComparer,
14921500
},
14931501
"compaction_cancellation": {
14941502
// Run at a specific version, so that a single sstable format is used,
14951503
// since the test prints the compaction log which includes file sizes.
14961504
minVersion: formatDeprecatedExperimentalValueSeparation,
14971505
maxVersion: formatDeprecatedExperimentalValueSeparation,
1506+
cmp: DefaultComparer,
14981507
},
14991508
"l0_to_lbase_compaction": {
15001509
minVersion: formatDeprecatedExperimentalValueSeparation,
15011510
maxVersion: formatDeprecatedExperimentalValueSeparation,
1511+
cmp: DefaultComparer,
15021512
},
15031513
"backing_value_size": {
15041514
minVersion: FormatBackingValueSize,
15051515
maxVersion: FormatBackingValueSize,
15061516
verbose: true,
1517+
cmp: DefaultComparer,
15071518
},
15081519
}
15091520
datadriven.Walk(t, "testdata/compaction", func(t *testing.T, path string) {
@@ -2767,21 +2778,6 @@ func TestMarkedForCompaction(t *testing.T) {
27672778
if testing.Verbose() {
27682779
eventListener = TeeEventListener(eventListener, MakeLoggingEventListener(base.DefaultLogger))
27692780
}
2770-
mkOpts := func() *Options {
2771-
opts := &Options{
2772-
FS: vfs.NewMem(),
2773-
DebugCheck: DebugCheckLevels,
2774-
DisableAutomaticCompactions: true,
2775-
FormatMajorVersion: internalFormatNewest,
2776-
EventListener: &eventListener,
2777-
Logger: testutils.Logger{T: t},
2778-
}
2779-
opts.Experimental.CompactionScheduler = func() CompactionScheduler {
2780-
return NewConcurrencyLimitSchedulerWithNoPeriodicGrantingForTest()
2781-
}
2782-
opts.WithFSDefaults()
2783-
return opts
2784-
}
27852781

27862782
var opts *Options
27872783
var d *DB
@@ -2810,11 +2806,18 @@ func TestMarkedForCompaction(t *testing.T) {
28102806

28112807
case "define":
28122808
if d != nil {
2813-
if err := d.Close(); err != nil {
2814-
return err.Error()
2815-
}
2809+
require.NoError(t, d.Close())
2810+
}
2811+
opts = &Options{
2812+
DebugCheck: DebugCheckLevels,
2813+
DisableAutomaticCompactions: true,
2814+
FormatMajorVersion: internalFormatNewest,
2815+
EventListener: &eventListener,
2816+
Logger: testutils.Logger{T: t},
2817+
}
2818+
opts.Experimental.CompactionScheduler = func() CompactionScheduler {
2819+
return NewConcurrencyLimitSchedulerWithNoPeriodicGrantingForTest()
28162820
}
2817-
opts = mkOpts()
28182821
var err error
28192822
if d, err = runDBDefineCmd(td, opts); err != nil {
28202823
return err.Error()

data_test.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -838,22 +838,16 @@ func runCompactCmd(td *datadriven.TestData, d *DB) error {
838838
// The resulting version edit is then manipulated to write the files
839839
// to the indicated level.
840840
//
841-
// Because of it's low-level manipulation, runDBDefineCmd does allow the
841+
// Because of its low-level manipulation, runDBDefineCmd does allow the
842842
// creation of invalid database states. If opts.DebugCheck is set, the
843843
// level checker should detect the invalid state.
844+
//
845+
// The given opts are modified if the test directive contains any options. If
846+
// opts.FS is nil, it is initialized to a new MemFS.
844847
func runDBDefineCmd(td *datadriven.TestData, opts *Options) (*DB, error) {
845-
if opts == nil {
846-
opts = &Options{}
848+
if opts.FS == nil {
849+
opts.FS = vfs.NewMem()
847850
}
848-
opts.EnsureDefaults()
849-
opts.FS = vfs.NewMem()
850-
return runDBDefineCmdReuseFS(td, opts)
851-
}
852-
853-
// runDBDefineCmdReuseFS is like runDBDefineCmd, but does not set opts.FS, expecting
854-
// the caller to have set an appropriate FS already.
855-
func runDBDefineCmdReuseFS(td *datadriven.TestData, opts *Options) (*DB, error) {
856-
opts.EnsureDefaults()
857851
if err := parseDBOptionsArgs(opts, td.CmdArgs); err != nil {
858852
return nil, err
859853
}
@@ -1005,13 +999,18 @@ func runDBDefineCmdReuseFS(td *datadriven.TestData, opts *Options) (*DB, error)
1005999
if len(parts) != 2 {
10061000
return nil, errors.Errorf("malformed table spec: %s", s)
10071001
}
1008-
m := (&manifest.TableMetadata{}).ExtendPointKeyBounds(
1009-
opts.Comparer.Compare,
1002+
var m manifest.TableMetadata
1003+
cmp := base.DefaultComparer.Compare
1004+
if opts.Comparer != nil {
1005+
cmp = opts.Comparer.Compare
1006+
}
1007+
m.ExtendPointKeyBounds(
1008+
cmp,
10101009
InternalKey{UserKey: []byte(parts[0])},
10111010
InternalKey{UserKey: []byte(parts[1])},
10121011
)
10131012
m.InitPhysicalBacking()
1014-
return m, nil
1013+
return &m, nil
10151014
}
10161015

10171016
// Example, compact: a-c.
@@ -1815,11 +1814,18 @@ func parseDBOptionsArgs(opts *Options, args []datadriven.CmdArg) error {
18151814
opts.TargetFileSizes[i] = size
18161815
}
18171816
// Set the remaining file sizes. Normally, EnsureDefaults() would do that
1818-
// for us but it was already called and the target file sizes for all
1817+
// for us but if it was already called the target file sizes for all
18191818
// levels are now set to the defaults.
18201819
for i := len(cmdArg.Vals); i < len(opts.TargetFileSizes); i++ {
18211820
opts.TargetFileSizes[i] = opts.TargetFileSizes[i-1] * 2
18221821
}
1822+
case "flush-split-bytes":
1823+
flushSplitBytes, err := strconv.ParseInt(cmdArg.Vals[0], 10, 64)
1824+
if err != nil {
1825+
return err
1826+
}
1827+
opts.FlushSplitBytes = flushSplitBytes
1828+
18231829
case "value-separation":
18241830
var policy ValueSeparationPolicy
18251831
if len(cmdArg.Vals) == 1 && cmdArg.Vals[0] == "off" || cmdArg.Vals[0] == "disabled" {

db_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ func TestDeterminism(t *testing.T) {
22722272
}
22732273
opts.Experimental.IngestSplit = func() bool { return rand.IntN(2) == 1 }
22742274
var err error
2275-
if d, err = runDBDefineCmdReuseFS(td, opts); err != nil {
2275+
if d, err = runDBDefineCmd(td, opts); err != nil {
22762276
return err.Error()
22772277
}
22782278
return d.mu.versions.currentVersion().String()

ingest_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,6 @@ func TestIngestTargetLevel(t *testing.T) {
16091609
opts := Options{
16101610
FormatMajorVersion: internalFormatNewest,
16111611
}
1612-
opts.WithFSDefaults()
16131612
if d, err = runDBDefineCmd(td, &opts); err != nil {
16141613
return err.Error()
16151614
}

lsm_view_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestLSMViewURL(t *testing.T) {
1515
func(t *testing.T, td *datadriven.TestData) string {
1616
switch td.Cmd {
1717
case "define":
18-
d, err := runDBDefineCmd(td, nil /* options */)
18+
d, err := runDBDefineCmd(td, &Options{})
1919
if err != nil {
2020
td.Fatalf(t, "error: %s", err)
2121
}

testdata/table_stats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ range-deletions-bytes-estimate: 78
262262

263263
# Test the interaction between point and range key deletions.
264264

265-
define block-size=1 target-file-sizes=(100, 1)
265+
define block-size=1 target-file-sizes=(100, 1) flush-split-bytes=1000000
266266
----
267267

268268
# Start with a table that contains point and range keys, but no range dels or

version_set_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,11 @@ func TestLargeKeys(t *testing.T) {
375375
}()
376376

377377
var d *DB
378-
defer func() { require.NoError(t, d.Close()) }()
378+
defer func() {
379+
if d != nil {
380+
require.NoError(t, d.Close())
381+
}
382+
}()
379383
datadriven.RunTest(t, "testdata/large_keys", func(t *testing.T, td *datadriven.TestData) string {
380384
switch td.Cmd {
381385
case "define":

0 commit comments

Comments
 (0)