Skip to content

Commit 00352d0

Browse files
committed
db: clean up test code for set-concurrent-compactions
We no longer require copying `CompactionConcurrencyRange` from the old options.
1 parent cc9d5be commit 00352d0

7 files changed

+35
-56
lines changed

compaction_test.go

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,6 @@ func runCompactionTest(
893893
) {
894894
defer leaktest.AfterTest(t)()
895895

896-
var mem vfs.FS
897896
var d *DB
898897
defer func() {
899898
if d != nil {
@@ -906,10 +905,6 @@ func runCompactionTest(
906905
rng := rand.New(rand.NewPCG(0, seed))
907906
t.Logf("seed: %d", seed)
908907

909-
randVersion := func(min, max FormatMajorVersion) FormatMajorVersion {
910-
return FormatMajorVersion(int(min) + rng.IntN(int(max)-int(min)+1))
911-
}
912-
913908
var compactionLog bytes.Buffer
914909
compactionLogEventListener := &EventListener{
915910
CompactionEnd: func(info CompactionInfo) {
@@ -920,31 +915,36 @@ func runCompactionTest(
920915
fmt.Fprintln(&compactionLog, info.String())
921916
},
922917
}
923-
reset := func(minVersion, maxVersion FormatMajorVersion, cmp *Comparer) {
924-
compactionLog.Reset()
925-
if d != nil {
926-
require.NoError(t, closeAllSnapshots(d))
927-
require.NoError(t, d.Close())
928-
}
929-
mem = vfs.NewMem()
930-
require.NoError(t, mem.MkdirAll("ext", 0755))
931-
918+
concurrencyLow, concurrencyHigh := 1, 1
919+
mkOpts := func() *Options {
920+
randVersion := FormatMajorVersion(int(minVersion) + rng.IntN(int(maxVersion)-int(minVersion)+1))
932921
opts := &Options{
933-
FS: mem,
922+
FS: vfs.NewMem(),
934923
DebugCheck: DebugCheckLevels,
935924
DisableAutomaticCompactions: true,
936925
EventListener: compactionLogEventListener,
937-
FormatMajorVersion: randVersion(minVersion, maxVersion),
926+
FormatMajorVersion: randVersion,
938927
Logger: testutils.Logger{T: t},
939928
Comparer: cmp,
929+
CompactionConcurrencyRange: func() (int, int) {
930+
return concurrencyLow, concurrencyHigh
931+
},
940932
}
941933
opts.WithFSDefaults()
942934
opts.Experimental.CompactionScheduler = func() CompactionScheduler {
943935
return NewConcurrencyLimitSchedulerWithNoPeriodicGrantingForTest()
944936
}
945-
937+
return opts
938+
}
939+
reset := func() {
940+
if d != nil {
941+
require.NoError(t, closeAllSnapshots(d))
942+
require.NoError(t, d.Close())
943+
}
944+
compactionLog.Reset()
945+
concurrencyLow, concurrencyHigh = 1, 1
946946
var err error
947-
d, err = Open("", opts)
947+
d, err = Open("", mkOpts())
948948
require.NoError(t, err)
949949
}
950950

@@ -986,12 +986,12 @@ func runCompactionTest(
986986
d.mu.compact.compactingCount--
987987
}
988988

989-
reset(minVersion, maxVersion, cmp)
989+
reset()
990990
var ongoingCompaction *tableCompaction
991991
datadriven.RunTest(t, testData, func(t *testing.T, td *datadriven.TestData) string {
992992
switch td.Cmd {
993993
case "reset":
994-
reset(minVersion, maxVersion, cmp)
994+
reset()
995995
return ""
996996

997997
case "batch":
@@ -1003,7 +1003,7 @@ func runCompactionTest(
10031003
return ""
10041004

10051005
case "build":
1006-
if err := runBuildCmd(td, d, mem); err != nil {
1006+
if err := runBuildCmd(td, d, d.opts.FS); err != nil {
10071007
return err.Error()
10081008
}
10091009
return ""
@@ -1025,36 +1025,12 @@ func runCompactionTest(
10251025

10261026
case "define":
10271027
if d != nil {
1028-
if err := closeAllSnapshots(d); err != nil {
1029-
return err.Error()
1030-
}
1031-
if err := d.Close(); err != nil {
1032-
return err.Error()
1033-
}
1034-
}
1035-
1036-
mem = vfs.NewMem()
1037-
opts := &Options{
1038-
FS: mem,
1039-
DebugCheck: DebugCheckLevels,
1040-
EventListener: compactionLogEventListener,
1041-
FormatMajorVersion: randVersion(minVersion, maxVersion),
1042-
DisableAutomaticCompactions: true,
1043-
Logger: testutils.Logger{T: t},
1044-
}
1045-
if cmp != nil {
1046-
opts.Comparer = cmp
1047-
}
1048-
opts.WithFSDefaults()
1049-
opts.Experimental.CompactionScheduler = func() CompactionScheduler {
1050-
return NewConcurrencyLimitSchedulerWithNoPeriodicGrantingForTest()
1051-
}
1052-
if d != nil {
1053-
opts.CompactionConcurrencyRange = d.opts.CompactionConcurrencyRange
1028+
require.NoError(t, closeAllSnapshots(d))
1029+
require.NoError(t, d.Close())
10541030
}
10551031

10561032
var err error
1057-
if d, err = runDBDefineCmd(td, opts); err != nil {
1033+
if d, err = runDBDefineCmd(td, mkOpts()); err != nil {
10581034
return err.Error()
10591035
}
10601036

@@ -1404,14 +1380,10 @@ func runCompactionTest(
14041380
return ""
14051381

14061382
case "set-concurrent-compactions":
1407-
lower := 1
1408-
upper := 1
1409-
td.MaybeScanArgs(t, "max", &upper)
1410-
td.MaybeScanArgs(t, "range", &lower, &upper)
1411-
d.opts.CompactionConcurrencyRange = func() (int, int) {
1412-
return lower, upper
1413-
}
1414-
return ""
1383+
concurrencyLow, concurrencyHigh = 1, 1
1384+
td.MaybeScanArgs(t, "max", &concurrencyHigh)
1385+
td.MaybeScanArgs(t, "range", &concurrencyLow, &concurrencyHigh)
1386+
return fmt.Sprintf("concurrency set to [%d, %d]", concurrencyLow, concurrencyHigh)
14151387

14161388
case "sstable-properties":
14171389
return runSSTablePropertiesCmd(t, td, d)

testdata/compaction/l0_to_lbase_compaction

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ define l0-compaction-threshold=1 auto-compactions=off
77

88
set-concurrent-compactions range=(3,3)
99
----
10+
concurrency set to [3, 3]
1011

1112

1213
populate keylen=4 timestamps=(1) vallen=1

testdata/compaction/multilevel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ L4:
3838
# Set concurrent compactions to 2 for the remainder of the tests.
3939
set-concurrent-compactions max=2
4040
----
41+
concurrency set to [1, 2]
4142

4243
define level-max-bytes=(L2 : 5) auto-compactions=off
4344
L1

testdata/compaction/set_with_del_sstable_Pebblev4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ add-ongoing-compaction startLevel=0 outputLevel=1 start=a end=z
644644

645645
set-concurrent-compactions max=2
646646
----
647+
concurrency set to [1, 2]
647648

648649
compact a-b L3
649650
----

testdata/compaction/set_with_del_sstable_Pebblev5

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ add-ongoing-compaction startLevel=0 outputLevel=1 start=a end=z
649649

650650
set-concurrent-compactions max=2
651651
----
652+
concurrency set to [1, 2]
652653

653654
compact a-b L3
654655
----

testdata/compaction/set_with_del_sstable_Pebblev6

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ add-ongoing-compaction startLevel=0 outputLevel=1 start=a end=z
649649

650650
set-concurrent-compactions max=2
651651
----
652+
concurrency set to [1, 2]
652653

653654
compact a-b L3
654655
----
@@ -672,6 +673,7 @@ L5:
672673
# Reset to default value of 1.
673674
set-concurrent-compactions max=1
674675
----
676+
concurrency set to [1, 1]
675677

676678

677679
# Test of a scenario where consecutive elided range tombstones and grandparent

testdata/compaction/set_with_del_sstable_Pebblev7

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ add-ongoing-compaction startLevel=0 outputLevel=1 start=a end=z
649649

650650
set-concurrent-compactions max=2
651651
----
652+
concurrency set to [1, 2]
652653

653654
compact a-b L3
654655
----

0 commit comments

Comments
 (0)