@@ -185,7 +185,8 @@ type pickedCompaction struct {
185
185
// levels that get compacted in multi level compactions
186
186
extraLevels []* compactionLevel
187
187
inputs []compactionLevel
188
- // LBase at the time of compaction picking.
188
+ // LBase at the time of compaction picking. Might be uninitialized for
189
+ // intra-L0 compactions.
189
190
baseLevel int
190
191
// L0-specific compaction info. Set to a non-nil value for all compactions
191
192
// where startLevel == 0 that were generated by L0Sublevels.
@@ -230,6 +231,9 @@ func newPickedCompaction(
230
231
l0Organizer * manifest.L0Organizer ,
231
232
startLevel , outputLevel , baseLevel int ,
232
233
) * pickedCompaction {
234
+ if outputLevel > 0 && baseLevel == 0 {
235
+ panic ("base level cannot be 0" )
236
+ }
233
237
if startLevel > 0 && startLevel < baseLevel {
234
238
panic (fmt .Sprintf ("invalid compaction: start level %d should not be empty (base level %d)" ,
235
239
startLevel , baseLevel ))
@@ -255,14 +259,16 @@ func newPickedCompaction(
255
259
// determining the target output file size, overlap bytes, and expanded
256
260
// bytes, taking into account the base level.
257
261
func adjustedOutputLevel (outputLevel int , baseLevel int ) int {
258
- adjustedOutputLevel := outputLevel
259
- if adjustedOutputLevel > 0 {
260
- // Output level is in the range [baseLevel, numLevels]. For the purpose of
261
- // determining the target output file size, overlap bytes, and expanded
262
- // bytes, we want to adjust the range to [1,numLevels].
263
- adjustedOutputLevel = 1 + outputLevel - baseLevel
264
- }
265
- return adjustedOutputLevel
262
+ if outputLevel == 0 {
263
+ return 0
264
+ }
265
+ if baseLevel == 0 {
266
+ panic ("base level cannot be 0" )
267
+ }
268
+ // Output level is in the range [baseLevel, numLevels). For the purpose of
269
+ // determining the target output file size, overlap bytes, and expanded
270
+ // bytes, we want to adjust the range to [1, numLevels).
271
+ return 1 + outputLevel - baseLevel
266
272
}
267
273
268
274
func newPickedCompactionFromL0 (
0 commit comments