Skip to content

Commit

Permalink
ingest: Call maybeScheduleFlush immediately in ingestApply
Browse files Browse the repository at this point in the history
Previously we would delay the call to maybeScheduleFlush
in ingestApply mostly out of readability. However it's safe
to call it directly as the flush will wait for the manifest
lock (which we are holding in that method) before it applies
anyway. Furthermore, calling it directly avoids a bug where
error cases in ingestApply could lead to us not scheduling
a flush for a flushable memtable.
  • Loading branch information
itsbilal committed Jun 15, 2023
1 parent e9a2803 commit 9f82737
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1611,14 +1611,16 @@ func (d *DB) ingestApply(
// returns must unlock the manifest.
d.mu.versions.logLock()

scheduleFlush := false
if mut != nil {
// Unref the mutable memtable to allows its flush to proceed. Now that we've
// acquired the manifest lock, we can be certain that if the mutable
// memtable has received more recent conflicting writes, the flush won't
// beat us to applying to the manifest resulting in sequence number
// inversion.
scheduleFlush = mut.writerUnref()
// inversion. Even though we call maybeScheduleFlush right now, this flush
// will apply after our ingestion.
if mut.writerUnref() {
d.maybeScheduleFlush()
}
}

current := d.mu.versions.currentVersion()
Expand Down Expand Up @@ -1734,9 +1736,6 @@ func (d *DB) ingestApply(
// The ingestion may have pushed a level over the threshold for compaction,
// so check to see if one is necessary and schedule it.
d.maybeScheduleCompaction()
if scheduleFlush {
d.maybeScheduleFlush()
}
d.maybeValidateSSTablesLocked(ve.NewFiles)
return ve, nil
}
Expand Down

0 comments on commit 9f82737

Please sign in to comment.