Skip to content

Commit d977e55

Browse files
committed
Don't let other compactions run when manual compaction runs
Summary: Based on discussions from t4982833. This is just a short-term fix, I plan to revamp manual compaction process as part of t4982812. Also, I think we should schedule automatic compactions at the very end of manual compactions, not when we're done with one level. I made that change as part of this diff. Let me know if you disagree. Test Plan: make check for now Reviewers: sdong, tnovak, yhchiang, ljin Reviewed By: yhchiang Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D22401
1 parent d5bd6c7 commit d977e55

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

db/db_impl.cc

+19-11
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,13 @@ Status DBImpl::CompactRange(ColumnFamilyHandle* column_family,
16771677
}
16781678
LogFlush(options_.info_log);
16791679

1680+
{
1681+
MutexLock l(&mutex_);
1682+
// an automatic compaction that has been scheduled might have been
1683+
// preempted by the manual compactions. Need to schedule it back.
1684+
MaybeScheduleFlushOrCompaction();
1685+
}
1686+
16801687
return s;
16811688
}
16821689

@@ -1864,18 +1871,15 @@ Status DBImpl::RunManualCompaction(ColumnFamilyData* cfd, int input_level,
18641871
bg_cv_.Wait();
18651872
} else {
18661873
manual_compaction_ = &manual;
1867-
MaybeScheduleFlushOrCompaction();
1874+
assert(bg_compaction_scheduled_ == 0);
1875+
bg_compaction_scheduled_++;
1876+
env_->Schedule(&DBImpl::BGWorkCompaction, this, Env::Priority::LOW);
18681877
}
18691878
}
18701879

18711880
assert(!manual.in_progress);
18721881
assert(bg_manual_only_ > 0);
18731882
--bg_manual_only_;
1874-
if (bg_manual_only_ == 0) {
1875-
// an automatic compaction should have been scheduled might have be
1876-
// preempted by the manual compactions. Need to schedule it back.
1877-
MaybeScheduleFlushOrCompaction();
1878-
}
18791883
return manual.status;
18801884
}
18811885

@@ -1963,11 +1967,11 @@ void DBImpl::MaybeScheduleFlushOrCompaction() {
19631967

19641968
// Schedule BGWorkCompaction if there's a compaction pending (or a memtable
19651969
// flush, but the HIGH pool is not enabled)
1966-
// Do it only if max_background_compactions hasn't been reached and, in case
1967-
// bg_manual_only_ > 0, if it's a manual compaction.
1968-
if ((manual_compaction_ || is_compaction_needed ||
1969-
(is_flush_pending && options_.max_background_flushes == 0)) &&
1970-
(!bg_manual_only_ || manual_compaction_)) {
1970+
// Do it only if max_background_compactions hasn't been reached and
1971+
// bg_manual_only_ == 0
1972+
if (!bg_manual_only_ &&
1973+
(is_compaction_needed ||
1974+
(is_flush_pending && options_.max_background_flushes == 0))) {
19711975
if (bg_compaction_scheduled_ < options_.max_background_compactions) {
19721976
bg_compaction_scheduled_++;
19731977
env_->Schedule(&DBImpl::BGWorkCompaction, this, Env::Priority::LOW);
@@ -2194,6 +2198,10 @@ Status DBImpl::BackgroundCompaction(bool* madeProgress,
21942198
if (is_manual) {
21952199
// another thread cannot pick up the same work
21962200
manual_compaction_->in_progress = true;
2201+
} else if (manual_compaction_ != nullptr) {
2202+
// there should be no automatic compactions running when manual compaction
2203+
// is running
2204+
return Status::OK();
21972205
}
21982206

21992207
// FLUSH preempts compaction

0 commit comments

Comments
 (0)