@@ -893,7 +893,6 @@ func runCompactionTest(
893
893
) {
894
894
defer leaktest .AfterTest (t )()
895
895
896
- var mem vfs.FS
897
896
var d * DB
898
897
defer func () {
899
898
if d != nil {
@@ -906,10 +905,6 @@ func runCompactionTest(
906
905
rng := rand .New (rand .NewPCG (0 , seed ))
907
906
t .Logf ("seed: %d" , seed )
908
907
909
- randVersion := func (min , max FormatMajorVersion ) FormatMajorVersion {
910
- return FormatMajorVersion (int (min ) + rng .IntN (int (max )- int (min )+ 1 ))
911
- }
912
-
913
908
var compactionLog bytes.Buffer
914
909
compactionLogEventListener := & EventListener {
915
910
CompactionEnd : func (info CompactionInfo ) {
@@ -920,31 +915,36 @@ func runCompactionTest(
920
915
fmt .Fprintln (& compactionLog , info .String ())
921
916
},
922
917
}
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 ))
932
921
opts := & Options {
933
- FS : mem ,
922
+ FS : vfs . NewMem () ,
934
923
DebugCheck : DebugCheckLevels ,
935
924
DisableAutomaticCompactions : true ,
936
925
EventListener : compactionLogEventListener ,
937
- FormatMajorVersion : randVersion ( minVersion , maxVersion ) ,
926
+ FormatMajorVersion : randVersion ,
938
927
Logger : testutils.Logger {T : t },
939
928
Comparer : cmp ,
929
+ CompactionConcurrencyRange : func () (int , int ) {
930
+ return concurrencyLow , concurrencyHigh
931
+ },
940
932
}
941
933
opts .WithFSDefaults ()
942
934
opts .Experimental .CompactionScheduler = func () CompactionScheduler {
943
935
return NewConcurrencyLimitSchedulerWithNoPeriodicGrantingForTest ()
944
936
}
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
946
946
var err error
947
- d , err = Open ("" , opts )
947
+ d , err = Open ("" , mkOpts () )
948
948
require .NoError (t , err )
949
949
}
950
950
@@ -986,12 +986,12 @@ func runCompactionTest(
986
986
d .mu .compact .compactingCount --
987
987
}
988
988
989
- reset (minVersion , maxVersion , cmp )
989
+ reset ()
990
990
var ongoingCompaction * tableCompaction
991
991
datadriven .RunTest (t , testData , func (t * testing.T , td * datadriven.TestData ) string {
992
992
switch td .Cmd {
993
993
case "reset" :
994
- reset (minVersion , maxVersion , cmp )
994
+ reset ()
995
995
return ""
996
996
997
997
case "batch" :
@@ -1003,7 +1003,7 @@ func runCompactionTest(
1003
1003
return ""
1004
1004
1005
1005
case "build" :
1006
- if err := runBuildCmd (td , d , mem ); err != nil {
1006
+ if err := runBuildCmd (td , d , d . opts . FS ); err != nil {
1007
1007
return err .Error ()
1008
1008
}
1009
1009
return ""
@@ -1025,36 +1025,12 @@ func runCompactionTest(
1025
1025
1026
1026
case "define" :
1027
1027
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 ())
1054
1030
}
1055
1031
1056
1032
var err error
1057
- if d , err = runDBDefineCmd (td , opts ); err != nil {
1033
+ if d , err = runDBDefineCmd (td , mkOpts () ); err != nil {
1058
1034
return err .Error ()
1059
1035
}
1060
1036
@@ -1404,14 +1380,10 @@ func runCompactionTest(
1404
1380
return ""
1405
1381
1406
1382
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 )
1415
1387
1416
1388
case "sstable-properties" :
1417
1389
return runSSTablePropertiesCmd (t , td , d )
0 commit comments