diff --git a/db/db_flush_test.cc b/db/db_flush_test.cc index 8a4d8fc63a..09c461f8da 100644 --- a/db/db_flush_test.cc +++ b/db/db_flush_test.cc @@ -488,6 +488,32 @@ TEST_P(DBAtomicFlushTest, Destroy(options); } +TEST_P(DBAtomicFlushTest, TriggerFlushAndClose) { + bool atomic_flush = GetParam(); + if (!atomic_flush) { + return; + } + const int kNumKeysTriggerFlush = 4; + Options options = CurrentOptions(); + options.create_if_missing = true; + options.atomic_flush = atomic_flush; + options.memtable_factory.reset( + new SpecialSkipListFactory(kNumKeysTriggerFlush)); + CreateAndReopenWithCF({"pikachu"}, options); + + for (int i = 0; i != kNumKeysTriggerFlush; ++i) { + ASSERT_OK(Put(0, "key" + std::to_string(i), "value" + std::to_string(i))); + } + SyncPoint::GetInstance()->DisableProcessing(); + SyncPoint::GetInstance()->ClearAllCallBacks(); + SyncPoint::GetInstance()->EnableProcessing(); + ASSERT_OK(Put(0, "key", "value")); + Close(); + + ReopenWithColumnFamilies({kDefaultColumnFamilyName, "pikachu"}, options); + ASSERT_EQ("value", Get(0, "key")); +} + INSTANTIATE_TEST_CASE_P(DBFlushDirectIOTest, DBFlushDirectIOTest, testing::Bool()); diff --git a/db/db_impl_compaction_flush.cc b/db/db_impl_compaction_flush.cc index 66ea247167..f16c611175 100644 --- a/db/db_impl_compaction_flush.cc +++ b/db/db_impl_compaction_flush.cc @@ -397,12 +397,21 @@ Status DBImpl::AtomicFlushMemTablesToOutputFiles( s = error_status.ok() ? s : error_status; } + // If db is NOT shutting down, and one or more column families have been + // dropped. + // TODO: use separate status code for db shutdown and column family dropped. + if (s.IsShutdownInProgress() && + !shutting_down_.load(std::memory_order_acquire)) { + s = Status::OK(); + } + if (s.ok() || s.IsShutdownInProgress()) { // Sync on all distinct output directories. for (auto dir : distinct_output_dirs) { if (dir != nullptr) { - s = dir->Fsync(); - if (!s.ok()) { + Status error_status = dir->Fsync(); + if (!error_status.ok()) { + s = error_status; break; } } @@ -469,7 +478,7 @@ Status DBImpl::AtomicFlushMemTablesToOutputFiles( &job_context->memtables_to_free, directories_.GetDbDir(), log_buffer); } - if (s.ok() || s.IsShutdownInProgress()) { + if (s.ok()) { assert(num_cfs == static_cast(job_context->superversion_contexts.size())); for (int i = 0; i != num_cfs; ++i) {