diff --git a/db/db_impl/db_impl_files.cc b/db/db_impl/db_impl_files.cc index 3c5fd4fcd7f..90fd54626e4 100644 --- a/db/db_impl/db_impl_files.cc +++ b/db/db_impl/db_impl_files.cc @@ -378,6 +378,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; @@ -477,11 +483,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_);