diff --git a/db/db_filesnapshot.cc b/db/db_filesnapshot.cc index 106ad01f999..db45481355f 100644 --- a/db/db_filesnapshot.cc +++ b/db/db_filesnapshot.cc @@ -36,6 +36,9 @@ Status DBImpl::FlushForGetLiveFiles() { Status status; FlushOptions opts; opts.allow_write_stall = true; + // In TiKV context: If tablet is to be destroyed, its background work will be + // paused. Manual flush can never make progress. + opts.check_if_compaction_disabled = true; if (immutable_db_options_.atomic_flush) { autovector cfds; SelectColumnFamiliesForAtomicFlush(&cfds); diff --git a/db/db_impl/db_impl.cc b/db/db_impl/db_impl.cc index 27b0b65d7da..1e99a175886 100644 --- a/db/db_impl/db_impl.cc +++ b/db/db_impl/db_impl.cc @@ -372,6 +372,7 @@ Status DBImpl::ResumeImpl(DBRecoverContext context) { FlushOptions flush_opts; // We allow flush to stall write since we are trying to resume from error. flush_opts.allow_write_stall = true; + flush_opts.check_if_compaction_disabled = true; if (immutable_db_options_.atomic_flush) { autovector cfds; SelectColumnFamiliesForAtomicFlush(&cfds); @@ -487,19 +488,21 @@ void DBImpl::CancelAllBackgroundWork(bool wait) { if (!shutting_down_.load(std::memory_order_acquire) && has_unpersisted_data_.load(std::memory_order_relaxed) && !mutable_db_options_.avoid_flush_during_shutdown) { + auto flush_opts = FlushOptions(); + flush_opts.allow_write_stall = true; + flush_opts.check_if_compaction_disabled = true; if (immutable_db_options_.atomic_flush) { autovector cfds; SelectColumnFamiliesForAtomicFlush(&cfds); mutex_.Unlock(); - Status s = - AtomicFlushMemTables(cfds, FlushOptions(), FlushReason::kShutDown); + Status s = AtomicFlushMemTables(cfds, flush_opts, FlushReason::kShutDown); s.PermitUncheckedError(); //**TODO: What to do on error? mutex_.Lock(); } else { for (auto cfd : versions_->GetRefedColumnFamilySet()) { if (!cfd->IsDropped() && cfd->initialized() && !cfd->mem()->IsEmpty()) { InstrumentedMutexUnlock u(&mutex_); - Status s = FlushMemTable(cfd, FlushOptions(), FlushReason::kShutDown); + Status s = FlushMemTable(cfd, flush_opts, FlushReason::kShutDown); s.PermitUncheckedError(); //**TODO: What to do on error? } } @@ -574,18 +577,20 @@ Status DBImpl::CloseHelper() { if (immutable_db_options_.experimental_mempurge_threshold > 0.0) { Status flush_ret; mutex_.Unlock(); + auto flush_opts = FlushOptions(); + flush_opts.allow_write_stall = true; + flush_opts.check_if_compaction_disabled = true; for (ColumnFamilyData* cf : *versions_->GetColumnFamilySet()) { if (immutable_db_options_.atomic_flush) { - flush_ret = AtomicFlushMemTables({cf}, FlushOptions(), - FlushReason::kManualFlush); + flush_ret = + AtomicFlushMemTables({cf}, flush_opts, FlushReason::kManualFlush); if (!flush_ret.ok()) { ROCKS_LOG_INFO( immutable_db_options_.info_log, "Atomic flush memtables failed upon closing (mempurge)."); } } else { - flush_ret = - FlushMemTable(cf, FlushOptions(), FlushReason::kManualFlush); + flush_ret = FlushMemTable(cf, flush_opts, FlushReason::kManualFlush); if (!flush_ret.ok()) { ROCKS_LOG_INFO(immutable_db_options_.info_log, "Flush memtables failed upon closing (mempurge)."); @@ -4811,6 +4816,7 @@ Status DBImpl::IngestExternalFiles( if (status.ok() && at_least_one_cf_need_flush) { FlushOptions flush_opts; flush_opts.allow_write_stall = true; + flush_opts.check_if_compaction_disabled = true; if (immutable_db_options_.atomic_flush) { autovector cfds_to_flush; SelectColumnFamiliesForAtomicFlush(&cfds_to_flush); diff --git a/db/db_impl/db_impl_compaction_flush.cc b/db/db_impl/db_impl_compaction_flush.cc index 4191665301c..9c476434657 100644 --- a/db/db_impl/db_impl_compaction_flush.cc +++ b/db/db_impl/db_impl_compaction_flush.cc @@ -1051,6 +1051,7 @@ Status DBImpl::CompactRangeInternal(const CompactRangeOptions& options, if (s.ok() && flush_needed) { FlushOptions fo; fo.allow_write_stall = options.allow_write_stall; + fo.check_if_compaction_disabled = true; if (immutable_db_options_.atomic_flush) { autovector cfds; mutex_.Lock();