diff --git a/HISTORY.md b/HISTORY.md index da1093612..7bcad2b84 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,9 @@ ### Behavior Changes * `DB::DestroyColumnFamilyHandle()` will return Status::InvalidArgument() if called with `DB::DefaultColumnFamily()`. +### Bug Fixes +* Fix a bug that FlushMemTable may return ok even flush not succeed. + ## 6.28.0 (2021-12-17) ### New Features * Introduced 'CommitWithTimestamp' as a new tag. Currently, there is no API for user to trigger a write with this tag to the WAL. This is part of the efforts to support write-commited transactions with user-defined timestamps. diff --git a/db/db_impl/db_impl_compaction_flush.cc b/db/db_impl/db_impl_compaction_flush.cc index 4152163d9..9c9f2eaa6 100644 --- a/db/db_impl/db_impl_compaction_flush.cc +++ b/db/db_impl/db_impl_compaction_flush.cc @@ -2264,21 +2264,27 @@ Status DBImpl::WaitForFlushMemTables( int num = static_cast(cfds.size()); // Wait until the compaction completes InstrumentedMutexLock l(&mutex_); + Status s; // If the caller is trying to resume from bg error, then // error_handler_.IsDBStopped() is true. while (resuming_from_bg_err || !error_handler_.IsDBStopped()) { if (shutting_down_.load(std::memory_order_acquire)) { - return Status::ShutdownInProgress(); + s = Status::ShutdownInProgress(); + return s; } // If an error has occurred during resumption, then no need to wait. + // But flush operation may fail because of this error, so need to + // return the status. if (!error_handler_.GetRecoveryError().ok()) { + s = error_handler_.GetRecoveryError(); break; } // If BGWorkStopped, which indicate that there is a BG error and // 1) soft error but requires no BG work, 2) no in auto_recovery_ if (!resuming_from_bg_err && error_handler_.IsBGWorkStopped() && error_handler_.GetBGError().severity() < Status::Severity::kHardError) { - return error_handler_.GetBGError(); + s = error_handler_.GetBGError(); + return s; } // Number of column families that have been dropped. @@ -2296,7 +2302,8 @@ Status DBImpl::WaitForFlushMemTables( } } if (1 == num_dropped && 1 == num) { - return Status::ColumnFamilyDropped(); + s = Status::ColumnFamilyDropped(); + return s; } // Column families involved in this flush request have either been dropped // or finished flush. Then it's time to finish waiting. @@ -2305,7 +2312,6 @@ Status DBImpl::WaitForFlushMemTables( } bg_cv_.Wait(); } - Status s; // If not resuming from bg error, and an error has caused the DB to stop, // then report the bg error to caller. if (!resuming_from_bg_err && error_handler_.IsDBStopped()) {