Skip to content

Commit 9c0e66c

Browse files
committed
Don't run background jobs (flush, compactions) when bg_error_ is set
Summary: If bg_error_ is set, that means that we mark DB read only. However, current behavior still continues the flushes and compactions, even though bg_error_ is set. On the other hand, if bg_error_ is set, we will return Status::OK() from CompactRange(), although the compaction didn't actually succeed. This is clearly not desired behavior. I found this when I was debugging t5132159, although I'm pretty sure these aren't related. Also, when we're shutting down, it's dangerous to exit RunManualCompaction(), since that will destruct ManualCompaction object. Background compaction job might still hold a reference to manual_compaction_ and this will lead to undefined behavior. I changed the behavior so that we only exit RunManualCompaction when manual compaction job is marked done. Test Plan: make check Reviewers: sdong, ljin, yhchiang Reviewed By: yhchiang Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D23223
1 parent a9639bd commit 9c0e66c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

db/db_impl.cc

+19-1
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,10 @@ Status DBImpl::RunManualCompaction(ColumnFamilyData* cfd, int input_level,
18911891
Log(db_options_.info_log, "[%s] Manual compaction starting",
18921892
cfd->GetName().c_str());
18931893

1894-
while (!manual.done && !shutting_down_.Acquire_Load() && bg_error_.ok()) {
1894+
// We don't check bg_error_ here, because if we get the error in compaction,
1895+
// the compaction will set manual.status to bg_error_ and set manual.done to
1896+
// true.
1897+
while (!manual.done) {
18951898
assert(bg_manual_only_ > 0);
18961899
if (manual_compaction_ != nullptr) {
18971900
// Running either this or some other manual compaction
@@ -2041,6 +2044,11 @@ Status DBImpl::BackgroundFlush(bool* madeProgress,
20412044
DeletionState& deletion_state,
20422045
LogBuffer* log_buffer) {
20432046
mutex_.AssertHeld();
2047+
2048+
if (!bg_error_.ok()) {
2049+
return bg_error_;
2050+
}
2051+
20442052
// call_status is failure if at least one flush was a failure. even if
20452053
// flushing one column family reports a failure, we will continue flushing
20462054
// other column families. however, call_status will be a failure in that case.
@@ -2228,6 +2236,16 @@ Status DBImpl::BackgroundCompaction(bool* madeProgress,
22282236
bool is_manual = (manual_compaction_ != nullptr) &&
22292237
(manual_compaction_->in_progress == false);
22302238

2239+
if (!bg_error_.ok()) {
2240+
if (is_manual) {
2241+
manual_compaction_->status = bg_error_;
2242+
manual_compaction_->done = true;
2243+
manual_compaction_->in_progress = false;
2244+
manual_compaction_ = nullptr;
2245+
}
2246+
return bg_error_;
2247+
}
2248+
22312249
if (is_manual) {
22322250
// another thread cannot pick up the same work
22332251
manual_compaction_->in_progress = true;

0 commit comments

Comments
 (0)