Skip to content

Commit aa5a248

Browse files
committed
db: refactor pickedCompaction into an interface
Refactor a pickedCompaction into an interface. With blob file rewriting, we can model picked blob-file rewrite compactions separately, as they share little of the same state as table compactions.
1 parent cca0dfd commit aa5a248

File tree

5 files changed

+196
-106
lines changed

5 files changed

+196
-106
lines changed

compaction.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ type getValueSeparation func(JobID, *compaction, sstable.TableFormat) compact.Va
395395
// The compaction is created with a reference to its version that must be
396396
// released when the compaction is complete.
397397
func newCompaction(
398-
pc *pickedCompaction,
398+
pc *pickedTableCompaction,
399399
opts *Options,
400400
beganAt time.Time,
401401
provider objstorage.Provider,
@@ -1926,7 +1926,7 @@ func (d *DB) makeCompactionEnvLocked() *compactionEnv {
19261926
}
19271927

19281928
// pickAnyCompaction tries to pick a manual or automatic compaction.
1929-
func (d *DB) pickAnyCompaction(env compactionEnv) (pc *pickedCompaction) {
1929+
func (d *DB) pickAnyCompaction(env compactionEnv) (pc pickedCompaction) {
19301930
// Pick a score-based compaction first, since a misshapen LSM is bad.
19311931
if !d.opts.DisableAutomaticCompactions {
19321932
if pc = d.mu.versions.picker.pickAutoScore(env); pc != nil {
@@ -1948,24 +1948,24 @@ func (d *DB) pickAnyCompaction(env compactionEnv) (pc *pickedCompaction) {
19481948
// is removed from d.mu.compact.manual.
19491949
//
19501950
// REQUIRES: d.mu and d.mu.versions.logLock is held.
1951-
func (d *DB) runPickedCompaction(pc *pickedCompaction, grantHandle CompactionGrantHandle) {
1951+
func (d *DB) runPickedCompaction(pc pickedCompaction, grantHandle CompactionGrantHandle) {
19521952
var doneChannel chan error
1953-
if pc.manualID > 0 {
1953+
if pc.ManualID() > 0 {
19541954
for i := range d.mu.compact.manual {
1955-
if d.mu.compact.manual[i].id == pc.manualID {
1955+
if d.mu.compact.manual[i].id == pc.ManualID() {
19561956
doneChannel = d.mu.compact.manual[i].done
19571957
d.mu.compact.manual = slices.Delete(d.mu.compact.manual, i, i+1)
19581958
d.mu.compact.manualLen.Store(int32(len(d.mu.compact.manual)))
19591959
break
19601960
}
19611961
}
19621962
if doneChannel == nil {
1963-
panic(errors.AssertionFailedf("did not find manual compaction with id %d", pc.manualID))
1963+
panic(errors.AssertionFailedf("did not find manual compaction with id %d", pc.ManualID()))
19641964
}
19651965
}
19661966

19671967
d.mu.compact.compactingCount++
1968-
compaction := newCompaction(pc, d.opts, d.timeNow(), d.ObjProvider(), grantHandle, d.TableFormat(), d.determineCompactionValueSeparation)
1968+
compaction := pc.ConstructCompaction(d, grantHandle)
19691969
d.addInProgressCompaction(compaction)
19701970
go func() {
19711971
d.compact(compaction, doneChannel)
@@ -2028,7 +2028,7 @@ func (d *DB) GetWaitingCompaction() (bool, WaitingCompaction) {
20282028
}
20292029
}
20302030
// INVARIANT: pc != nil and is in the cache.
2031-
return true, makeWaitingCompaction(pc.manualID > 0, pc.kind, pc.score)
2031+
return true, pc.WaitingCompaction()
20322032
}
20332033

20342034
// GetAllowedWithoutPermission implements DBForCompaction (it is called by the
@@ -2072,7 +2072,7 @@ func (d *DB) tryScheduleDownloadCompactions(env compactionEnv, maxConcurrentDown
20722072
return started
20732073
}
20742074

2075-
func (d *DB) pickManualCompaction(env compactionEnv) (pc *pickedCompaction) {
2075+
func (d *DB) pickManualCompaction(env compactionEnv) (pc pickedCompaction) {
20762076
v := d.mu.versions.currentVersion()
20772077
for len(d.mu.compact.manual) > 0 {
20782078
manual := d.mu.compact.manual[0]

0 commit comments

Comments
 (0)