@@ -34,16 +34,7 @@ func loadVersion(
3434 opts := & Options {}
3535 opts .testingRandomized (t )
3636 opts .EnsureDefaults ()
37-
38- if len (d .CmdArgs ) != 1 {
39- return nil , nil , nil , fmt .Sprintf ("%s expects 1 argument" , d .Cmd )
40- }
41- var err error
42- opts .LBaseMaxBytes , err = strconv .ParseInt (d .CmdArgs [0 ].Key , 10 , 64 )
43- if err != nil {
44- return nil , nil , nil , err .Error ()
45- }
46-
37+ d .ScanArgs (t , "l-base-max-bytes" , & opts .LBaseMaxBytes )
4738 var files [numLevels ][]* tableMetadata
4839 if len (d .Input ) > 0 {
4940 // Parse each line as
@@ -190,15 +181,16 @@ func TestCompactionPickerTargetLevel(t *testing.T) {
190181 f .CompactionState = manifest .CompactionStateNotCompacting
191182 }
192183 }
184+ l0Organizer .ResetForTesting (vers )
193185 }
194186
195- pickAuto := func (env compactionEnv , pickerByScore * compactionPickerByScore ) * pickedCompaction {
187+ pickAuto := func (env compactionEnv , pickerByScore * compactionPickerByScore ) ( pc * pickedCompaction , allowedCompactions int ) {
196188 inProgressCompactions := len (env .inProgressCompactions )
197- allowedCompactions : = pickerByScore .getCompactionConcurrency ()
189+ allowedCompactions = pickerByScore .getCompactionConcurrency ()
198190 if inProgressCompactions >= allowedCompactions {
199- return nil
191+ return nil , allowedCompactions
200192 }
201- return pickerByScore .pickAutoScore (env )
193+ return pickerByScore .pickAutoScore (env ), allowedCompactions
202194 }
203195
204196 datadriven .RunTest (t , "testdata/compaction_picker_target_level" ,
@@ -211,18 +203,26 @@ func TestCompactionPickerTargetLevel(t *testing.T) {
211203 // and optionally additional compensation to be added during
212204 // compensated file size calculations. Eg:
213205 //
214- // init <LBaseMaxBytes>
206+ // init l-base-max-bytes= <LBaseMaxBytes>
215207 // <level>: <size> [compensation]
216208 // <level>: <size> [compensation]
217209 var errMsg string
218210 vers , l0Organizer , opts , errMsg = loadVersion (t , d )
211+ // This test limits the count based on the L0 read amp, compaction
212+ // debt, and deleted garbage, so we would like to return math.MaxInt
213+ // for most test cases. But we don't since it is also used in
214+ // expandedCompactionByteSizeLimit, and causes the expanded bytes to
215+ // reduce. The test cases never pick more than 4 compactions, so we
216+ // use 4 as the default.
217+ maxConcurrentCompactions := 4
218+ if d .HasArg ("max-concurrent-compactions" ) {
219+ d .ScanArgs (t , "max-concurrent-compactions" , & maxConcurrentCompactions )
220+ }
219221 opts .MaxConcurrentCompactions = func () int {
220- // This test only limits the count based on the L0 read amp and
221- // compaction debt, so we would like to return math.MaxInt. But we
222- // don't since it is also used in expandedCompactionByteSizeLimit,
223- // and causes the expanded bytes to reduce. The test cases never
224- // pick more than 4 compactions, so we use 4.
225- return 4
222+ return maxConcurrentCompactions
223+ }
224+ if d .HasArg ("compaction-debt-concurrency" ) {
225+ d .ScanArgs (t , "compaction-debt-concurrency" , & opts .Experimental .CompactionDebtConcurrency )
226226 }
227227 if errMsg != "" {
228228 return errMsg
@@ -246,13 +246,20 @@ func TestCompactionPickerTargetLevel(t *testing.T) {
246246 case "queue" :
247247 var b strings.Builder
248248 var inProgress []compactionInfo
249+ printConcurrency := false
250+ if d .HasArg ("print-compaction-concurrency" ) {
251+ printConcurrency = true
252+ }
249253 for {
250254 env := compactionEnv {
251255 diskAvailBytes : math .MaxUint64 ,
252256 earliestUnflushedSeqNum : base .SeqNumMax ,
253257 inProgressCompactions : inProgress ,
254258 }
255- pc := pickAuto (env , pickerByScore )
259+ pc , concurrency := pickAuto (env , pickerByScore )
260+ if printConcurrency {
261+ fmt .Fprintf (& b , "compaction concurrency: %d\n " , concurrency )
262+ }
256263 if pc == nil {
257264 break
258265 }
@@ -268,6 +275,10 @@ func TestCompactionPickerTargetLevel(t *testing.T) {
268275 // because the test isn't marking files as Compacting.
269276 break
270277 }
278+ if pc .startLevel != nil && pc .startLevel .level == 0 {
279+ require .NoError (t , l0Organizer .UpdateStateForStartedCompaction (
280+ []manifest.LevelSlice {pc .startLevel .files }, true /* isBase */ ))
281+ }
271282 for _ , cl := range pc .inputs {
272283 for f := range cl .files .All () {
273284 f .CompactionState = manifest .CompactionStateCompacting
@@ -336,7 +347,7 @@ func TestCompactionPickerTargetLevel(t *testing.T) {
336347
337348 var b strings.Builder
338349 fmt .Fprintf (& b , "Initial state before pick:\n %s" , runVersionFileSizes (vers ))
339- pc := pickAuto (compactionEnv {
350+ pc , _ := pickAuto (compactionEnv {
340351 earliestUnflushedSeqNum : base .SeqNumMax ,
341352 inProgressCompactions : inProgress ,
342353 }, pickerByScore )
0 commit comments