diff --git a/db/column_family.cc b/db/column_family.cc index 4a600f611..b39518e08 100644 --- a/db/column_family.cc +++ b/db/column_family.cc @@ -59,6 +59,7 @@ ColumnFamilyHandleImpl::~ColumnFamilyHandleImpl() { if (job_context.HaveSomethingToDelete()) { db_->PurgeObsoleteFiles(job_context); } + job_context.Clean(); } } diff --git a/db/db_impl.cc b/db/db_impl.cc index c599f1ef2..66eac6ad0 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -542,6 +542,7 @@ void DBImpl::FindObsoleteFiles(JobContext* job_context, bool force, } // We're just cleaning up for DB::Write(). + assert(job_context->logs_to_free.empty()); job_context->logs_to_free = logs_to_free_; logs_to_free_.clear(); diff --git a/db/db_test.cc b/db/db_test.cc index 9a8fe6d9e..cb919c09f 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -12670,6 +12670,7 @@ TEST_F(DBTest, DontDeletePendingOutputs) { dbfull()->FindObsoleteFiles(&job_context, true /*force*/); dbfull()->TEST_UnlockMutex(); dbfull()->PurgeObsoleteFiles(job_context); + job_context.Clean(); }; env_->table_write_callback_ = &purge_obsolete_files_function; diff --git a/db/forward_iterator.cc b/db/forward_iterator.cc index b4410199e..5ed125930 100644 --- a/db/forward_iterator.cc +++ b/db/forward_iterator.cc @@ -169,6 +169,7 @@ void ForwardIterator::Cleanup(bool release_sv) { if (job_context.HaveSomethingToDelete()) { db_->PurgeObsoleteFiles(job_context); } + job_context.Clean(); } } } diff --git a/db/job_context.h b/db/job_context.h index d0281443e..5a54e2d85 100644 --- a/db/job_context.h +++ b/db/job_context.h @@ -83,6 +83,10 @@ struct JobContext { new_superversion = create_superversion ? new SuperVersion() : nullptr; } + // For non-empty JobContext Clean() has to be called at least once before + // before destruction (see asserts in ~JobContext()). Should be called with + // unlocked DB mutex. Destructor doesn't call Clean() to avoid accidentally + // doing potentially slow Clean() with locked DB mutex. void Clean() { // free pending memtables for (auto m : memtables_to_free) { @@ -109,6 +113,7 @@ struct JobContext { assert(memtables_to_free.size() == 0); assert(superversions_to_free.size() == 0); assert(new_superversion == nullptr); + assert(logs_to_free.size() == 0); } };