@@ -50,10 +50,8 @@ type compactionPicker interface {
5050 getScores ([]compactionInfo ) [numLevels ]float64
5151 getBaseLevel () int
5252 estimatedCompactionDebt (l0ExtraSize uint64 ) uint64
53- pickAuto (env compactionEnv ) (pc * pickedCompaction )
54- pickElisionOnlyCompaction (env compactionEnv ) (pc * pickedCompaction )
55- pickRewriteCompaction (env compactionEnv ) (pc * pickedCompaction )
56- pickReadTriggeredCompaction (env compactionEnv ) (pc * pickedCompaction )
53+ pickAutoScore (env compactionEnv ) (pc * pickedCompaction )
54+ pickAutoNonScore (env compactionEnv ) (pc * pickedCompaction )
5755 forceBaseLevel1 ()
5856}
5957
@@ -1244,70 +1242,71 @@ func (p *compactionPickerByScore) getCompactionConcurrency() int {
12441242 return max (min (maxConcurrentCompactions , max (l0ReadAmpCompactions , compactionDebtCompactions )), 1 )
12451243}
12461244
1247- // pickAuto picks the best compaction, if any.
1248- //
1249- // On each call, pickAuto computes per-level size adjustments based on
1250- // in-progress compactions, and computes a per-level score. The levels are
1251- // iterated over in decreasing score order trying to find a valid compaction
1252- // anchored at that level.
1253- //
1254- // If a score-based compaction cannot be found, pickAuto falls back to looking
1255- // for an elision-only compaction to remove obsolete keys.
1256- func (p * compactionPickerByScore ) pickAuto (env compactionEnv ) (pc * pickedCompaction ) {
1257- scores := p .calculateLevelScores (env .inProgressCompactions )
1245+ // TODO(sumeer): remove unless someone actually finds this useful.
1246+ func (p * compactionPickerByScore ) logCompactionForTesting (
1247+ env compactionEnv , scores [numLevels ]candidateLevelInfo , pc * pickedCompaction ,
1248+ ) {
1249+ var buf bytes.Buffer
1250+ for i := 0 ; i < numLevels ; i ++ {
1251+ if i != 0 && i < p .baseLevel {
1252+ continue
1253+ }
12581254
1259- // TODO(bananabrick): Either remove, or change this into an event sent to the
1260- // EventListener.
1261- logCompaction := func (pc * pickedCompaction ) {
1262- var buf bytes.Buffer
1263- for i := 0 ; i < numLevels ; i ++ {
1264- if i != 0 && i < p .baseLevel {
1265- continue
1255+ var info * candidateLevelInfo
1256+ for j := range scores {
1257+ if scores [j ].level == i {
1258+ info = & scores [j ]
1259+ break
12661260 }
1261+ }
12671262
1268- var info * candidateLevelInfo
1269- for j := range scores {
1270- if scores [j ].level == i {
1271- info = & scores [j ]
1272- break
1273- }
1274- }
1263+ marker := " "
1264+ if pc .startLevel .level == info .level {
1265+ marker = "*"
1266+ }
1267+ fmt .Fprintf (& buf , " %sL%d: %5.1f %5.1f %5.1f %5.1f %8s %8s" ,
1268+ marker , info .level , info .compensatedScoreRatio , info .compensatedScore ,
1269+ info .uncompensatedScoreRatio , info .uncompensatedScore ,
1270+ humanize .Bytes .Int64 (int64 (totalCompensatedSize (
1271+ p .vers .Levels [info .level ].All (),
1272+ ))),
1273+ humanize .Bytes .Int64 (p .levelMaxBytes [info .level ]),
1274+ )
12751275
1276- marker := " "
1277- if pc .startLevel .level == info .level {
1278- marker = "*"
1279- }
1280- fmt .Fprintf (& buf , " %sL%d: %5.1f %5.1f %5.1f %5.1f %8s %8s" ,
1281- marker , info .level , info .compensatedScoreRatio , info .compensatedScore ,
1282- info .uncompensatedScoreRatio , info .uncompensatedScore ,
1283- humanize .Bytes .Int64 (int64 (totalCompensatedSize (
1284- p .vers .Levels [info .level ].All (),
1285- ))),
1286- humanize .Bytes .Int64 (p .levelMaxBytes [info .level ]),
1287- )
1288-
1289- count := 0
1290- for i := range env .inProgressCompactions {
1291- c := & env .inProgressCompactions [i ]
1292- if c .inputs [0 ].level != info .level {
1293- continue
1294- }
1295- count ++
1296- if count == 1 {
1297- fmt .Fprintf (& buf , " [" )
1298- } else {
1299- fmt .Fprintf (& buf , " " )
1300- }
1301- fmt .Fprintf (& buf , "L%d->L%d" , c .inputs [0 ].level , c .outputLevel )
1276+ count := 0
1277+ for i := range env .inProgressCompactions {
1278+ c := & env .inProgressCompactions [i ]
1279+ if c .inputs [0 ].level != info .level {
1280+ continue
13021281 }
1303- if count > 0 {
1304- fmt .Fprintf (& buf , "]" )
1282+ count ++
1283+ if count == 1 {
1284+ fmt .Fprintf (& buf , " [" )
1285+ } else {
1286+ fmt .Fprintf (& buf , " " )
13051287 }
1306- fmt .Fprintf (& buf , "\n " )
1288+ fmt .Fprintf (& buf , "L%d->L%d" , c . inputs [ 0 ]. level , c . outputLevel )
13071289 }
1308- p .opts .Logger .Infof ("pickAuto: L%d->L%d\n %s" ,
1309- pc .startLevel .level , pc .outputLevel .level , buf .String ())
1290+ if count > 0 {
1291+ fmt .Fprintf (& buf , "]" )
1292+ }
1293+ fmt .Fprintf (& buf , "\n " )
13101294 }
1295+ p .opts .Logger .Infof ("pickAuto: L%d->L%d\n %s" ,
1296+ pc .startLevel .level , pc .outputLevel .level , buf .String ())
1297+ }
1298+
1299+ // pickAutoScore picks the best score-based compaction, if any.
1300+ //
1301+ // On each call, pickAutoScore computes per-level size adjustments based on
1302+ // in-progress compactions, and computes a per-level score. The levels are
1303+ // iterated over in decreasing score order trying to find a valid compaction
1304+ // anchored at that level.
1305+ //
1306+ // If a score-based compaction cannot be found, pickAuto falls back to looking
1307+ // for an elision-only compaction to remove obsolete keys.
1308+ func (p * compactionPickerByScore ) pickAutoScore (env compactionEnv ) (pc * pickedCompaction ) {
1309+ scores := p .calculateLevelScores (env .inProgressCompactions )
13111310
13121311 // Check for a score-based compaction. candidateLevelInfos are first sorted
13131312 // by whether they should be compacted, so if we find a level which shouldn't
@@ -1328,9 +1327,8 @@ func (p *compactionPickerByScore) pickAuto(env compactionEnv) (pc *pickedCompact
13281327 if pc != nil && ! inputRangeAlreadyCompacting (env , pc ) {
13291328 p .addScoresToPickedCompactionMetrics (pc , scores )
13301329 pc .score = info .compensatedScoreRatio
1331- // TODO(bananabrick): Create an EventListener for logCompaction.
13321330 if false {
1333- logCompaction ( pc )
1331+ p . logCompactionForTesting ( env , scores , pc )
13341332 }
13351333 return pc
13361334 }
@@ -1349,14 +1347,17 @@ func (p *compactionPickerByScore) pickAuto(env compactionEnv) (pc *pickedCompact
13491347 if pc != nil && ! inputRangeAlreadyCompacting (env , pc ) {
13501348 p .addScoresToPickedCompactionMetrics (pc , scores )
13511349 pc .score = info .compensatedScoreRatio
1352- // TODO(bananabrick): Create an EventListener for logCompaction.
13531350 if false {
1354- logCompaction ( pc )
1351+ p . logCompactionForTesting ( env , scores , pc )
13551352 }
13561353 return pc
13571354 }
13581355 }
1356+ return nil
1357+ }
13591358
1359+ // pickAutoNonScore picks the best non-score-based compaction, if any.
1360+ func (p * compactionPickerByScore ) pickAutoNonScore (env compactionEnv ) (pc * pickedCompaction ) {
13601361 // Check for files which contain excessive point tombstones that could slow
13611362 // down reads. Unlike elision-only compactions, these compactions may select
13621363 // a file at any level rather than only the lowest level.
0 commit comments