diff --git a/db/db_impl/db_impl.h b/db/db_impl/db_impl.h index 09c10496a..e970761f4 100644 --- a/db/db_impl/db_impl.h +++ b/db/db_impl/db_impl.h @@ -1554,6 +1554,10 @@ class DBImpl : public DB { uint64_t* log_used, SequenceNumber* last_sequence, size_t seq_inc); + // Used by WriteImpl to update bg_error_ if paranoid check is enabled. + // Caller must hold mutex_. + void WriteStatusCheckOnLocked(const Status& status); + // Used by WriteImpl to update bg_error_ if paranoid check is enabled. void WriteStatusCheck(const Status& status); diff --git a/db/db_impl/db_impl_write.cc b/db/db_impl/db_impl_write.cc index 9933d26a0..2ff3a81e8 100644 --- a/db/db_impl/db_impl_write.cc +++ b/db/db_impl/db_impl_write.cc @@ -623,8 +623,6 @@ Status DBImpl::UnorderedWriteMemtable(const WriteOptions& write_options, 0 /*log_number*/, this, true /*concurrent_memtable_writes*/, seq_per_batch_, sub_batch_cnt, true /*batch_per_txn*/, write_options.memtable_insert_hint_per_batch); - - WriteStatusCheck(w.status); if (write_options.disableWAL) { has_unpersisted_data_.store(true, std::memory_order_relaxed); } @@ -639,6 +637,7 @@ Status DBImpl::UnorderedWriteMemtable(const WriteOptions& write_options, std::lock_guard lck(switch_mutex_); switch_cv_.notify_all(); } + WriteStatusCheck(w.status); if (!w.FinalStatus().ok()) { return w.FinalStatus(); @@ -689,7 +688,7 @@ Status DBImpl::WriteImplWALOnly( InstrumentedMutexLock l(&mutex_); bool need_log_sync = false; status = PreprocessWrite(write_options, &need_log_sync, &write_context); - WriteStatusCheck(status); + WriteStatusCheckOnLocked(status); } if (!status.ok()) { WriteThread::WriteGroup write_group; @@ -830,6 +829,17 @@ Status DBImpl::WriteImplWALOnly( return status; } +void DBImpl::WriteStatusCheckOnLocked(const Status& status) { + // Is setting bg_error_ enough here? This will at least stop + // compaction and fail any further writes. + // Caller must hold mutex_. + mutex_.AssertHeld(); + if (immutable_db_options_.paranoid_checks && !status.ok() && + !status.IsBusy() && !status.IsIncomplete()) { + error_handler_.SetBGError(status, BackgroundErrorReason::kWriteCallback); + } +} + void DBImpl::WriteStatusCheck(const Status& status) { // Is setting bg_error_ enough here? This will at least stop // compaction and fail any further writes.