diff --git a/db/db_impl/db_impl_files.cc b/db/db_impl/db_impl_files.cc index 670d8e731..1fa288406 100644 --- a/db/db_impl/db_impl_files.cc +++ b/db/db_impl/db_impl_files.cc @@ -379,6 +379,12 @@ void DBImpl::PurgeObsoleteFiles(JobContext& state, bool schedule_only) { } } + // Close WALs before trying to delete them. + for (const auto w : state.logs_to_free) { + // TODO: maybe check the return value of Close. + w->Close(); + } + std::unordered_set files_to_del; for (const auto& candidate_file : candidate_files) { const std::string& to_delete = candidate_file.file_name; @@ -478,11 +484,6 @@ void DBImpl::PurgeObsoleteFiles(JobContext& state, bool schedule_only) { } #endif // !ROCKSDB_LITE - for (const auto w : state.logs_to_free) { - // TODO: maybe check the return value of Close. - w->Close(); - } - Status file_deletion_status; if (schedule_only) { InstrumentedMutexLock guard_lock(&mutex_);