@@ -599,16 +599,14 @@ func canCompactTables(
599
599
// installed).
600
600
func newCompactionPickerByScore (
601
601
v * manifest.Version ,
602
- l0Organizer * manifest.L0Organizer ,
603
- virtualBackings * manifest.VirtualBackings ,
602
+ lvs * latestVersionState ,
604
603
opts * Options ,
605
604
inProgressCompactions []compactionInfo ,
606
605
) * compactionPickerByScore {
607
606
p := & compactionPickerByScore {
608
- opts : opts ,
609
- vers : v ,
610
- l0Organizer : l0Organizer ,
611
- virtualBackings : virtualBackings ,
607
+ opts : opts ,
608
+ vers : v ,
609
+ latestVersionState : lvs ,
612
610
}
613
611
p .initLevelMaxBytes (inProgressCompactions )
614
612
return p
@@ -694,16 +692,16 @@ func totalCompensatedSize(iter iter.Seq[*manifest.TableMetadata]) uint64 {
694
692
type compactionPickerByScore struct {
695
693
opts * Options
696
694
vers * manifest.Version
697
- // Unlike vers, which is immutable and the latest version when this picker is
698
- // created, l0Organizer represents the mutable L0 state of the latest version.
699
- // This means that at some point in the future a compactionPickerByScore
700
- // created in the past will have mutually inconsistent state in vers and
701
- // l0Organizer . This is not a problem since (a) a new picker is created in
702
- // UpdateVersionLocked when a new version is installed, and (b) only the
703
- // latest picker is used for picking compactions. This is ensured by holding
704
- // versionSet.logLock for both (a) and (b).
705
- l0Organizer * manifest. L0Organizer
706
- virtualBackings * manifest. VirtualBackings
695
+ // Unlike vers, which is immutable and the latest version when this picker
696
+ // is created, latestVersionState represents the mutable state of the latest
697
+ // version. This means that at some point in the future a
698
+ // compactionPickerByScore created in the past will have mutually
699
+ // inconsistent state in vers and latestVersionState . This is not a problem
700
+ // since (a) a new picker is created in UpdateVersionLocked when a new
701
+ // version is installed, and (b) only the latest picker is used for picking
702
+ // compactions. This is ensured by holding versionSet.logLock for both (a)
703
+ // and (b).
704
+ latestVersionState * latestVersionState
707
705
// The level to target for L0 compactions. Levels L1 to baseLevel must be
708
706
// empty.
709
707
baseLevel int
@@ -939,7 +937,7 @@ func (p *compactionPickerByScore) calculateLevelScores(
939
937
scores [i ].level = i
940
938
scores [i ].outputLevel = i + 1
941
939
}
942
- l0FillFactor := calculateL0FillFactor (p .vers , p .l0Organizer , p .opts , inProgressCompactions )
940
+ l0FillFactor := calculateL0FillFactor (p .vers , p .latestVersionState . l0Organizer , p .opts , inProgressCompactions )
943
941
scores [0 ] = candidateLevelInfo {
944
942
outputLevel : p .baseLevel ,
945
943
fillFactor : l0FillFactor ,
@@ -1268,7 +1266,7 @@ func (p *compactionPickerByScore) getCompactionConcurrency() int {
1268
1266
// l0ReadAmp / p.opts.Experimental.L0CompactionConcurrency extra compactions.
1269
1267
l0ReadAmpCompactions := 0
1270
1268
if p .opts .Experimental .L0CompactionConcurrency > 0 {
1271
- l0ReadAmp := p .l0Organizer .MaxDepthAfterOngoingCompactions ()
1269
+ l0ReadAmp := p .latestVersionState . l0Organizer .MaxDepthAfterOngoingCompactions ()
1272
1270
l0ReadAmpCompactions = (l0ReadAmp / p .opts .Experimental .L0CompactionConcurrency )
1273
1271
}
1274
1272
// compactionDebt >= ccSignal2 then can run another compaction, where
@@ -1378,7 +1376,7 @@ func (p *compactionPickerByScore) pickAutoScore(env compactionEnv) (pc *pickedCo
1378
1376
}
1379
1377
1380
1378
if info .level == 0 {
1381
- pc = pickL0 (env , p .opts , p .vers , p .l0Organizer , p .baseLevel )
1379
+ pc = pickL0 (env , p .opts , p .vers , p .latestVersionState . l0Organizer , p .baseLevel )
1382
1380
// Fail-safe to protect against compacting the same sstable
1383
1381
// concurrently.
1384
1382
if pc != nil && ! inputRangeAlreadyCompacting (env , pc ) {
@@ -1394,12 +1392,12 @@ func (p *compactionPickerByScore) pickAutoScore(env compactionEnv) (pc *pickedCo
1394
1392
1395
1393
// info.level > 0
1396
1394
var ok bool
1397
- info .file , ok = pickCompactionSeedFile (p .vers , p .virtualBackings , p .opts , info .level , info .outputLevel , env .earliestSnapshotSeqNum , env .problemSpans )
1395
+ info .file , ok = pickCompactionSeedFile (p .vers , & p . latestVersionState .virtualBackings , p .opts , info .level , info .outputLevel , env .earliestSnapshotSeqNum , env .problemSpans )
1398
1396
if ! ok {
1399
1397
continue
1400
1398
}
1401
1399
1402
- pc := pickAutoLPositive (env , p .opts , p .vers , p .l0Organizer , * info , p .baseLevel )
1400
+ pc := pickAutoLPositive (env , p .opts , p .vers , p .latestVersionState . l0Organizer , * info , p .baseLevel )
1403
1401
// Fail-safe to protect against compacting the same sstable concurrently.
1404
1402
if pc != nil && ! inputRangeAlreadyCompacting (env , pc ) {
1405
1403
p .addScoresToPickedCompactionMetrics (pc , scores )
@@ -1583,7 +1581,8 @@ func (p *compactionPickerByScore) pickedCompactionFromCandidateFile(
1583
1581
}
1584
1582
}
1585
1583
1586
- pc := newPickedCompaction (p .opts , p .vers , p .l0Organizer , startLevel , outputLevel , p .baseLevel )
1584
+ pc := newPickedCompaction (p .opts , p .vers , p .latestVersionState .l0Organizer ,
1585
+ startLevel , outputLevel , p .baseLevel )
1587
1586
pc .kind = kind
1588
1587
pc .startLevel .files = inputs
1589
1588
pc .smallest , pc .largest = manifest .KeyRange (pc .cmp , pc .startLevel .files .All ())
@@ -2030,7 +2029,8 @@ func pickReadTriggeredCompactionHelper(
2030
2029
return nil
2031
2030
}
2032
2031
2033
- pc = newPickedCompaction (p .opts , p .vers , p .l0Organizer , rc .level , defaultOutputLevel (rc .level , p .baseLevel ), p .baseLevel )
2032
+ pc = newPickedCompaction (p .opts , p .vers , p .latestVersionState .l0Organizer ,
2033
+ rc .level , defaultOutputLevel (rc .level , p .baseLevel ), p .baseLevel )
2034
2034
2035
2035
pc .startLevel .files = overlapSlice
2036
2036
if ! pc .setupInputs (p .opts , env .diskAvailBytes , pc .startLevel , env .problemSpans ) {
0 commit comments