diff --git a/HISTORY.md b/HISTORY.md index f11553fe6..9b5e60279 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,9 @@ ### Public API Changes * Add `MakeSharedCache()` construction functions to various cache Options objects, and deprecated the `NewWhateverCache()` functions with long parameter lists. +### Bug Fixes +* Delete an empty WAL file on DB open if the log number is less than the min log number to keep + ## 8.2.0 (04/24/2023) ### Public API Changes * `SstFileWriter::DeleteRange()` now returns `Status::InvalidArgument` if the range's end key comes before its start key according to the user comparator. Previously the behavior was undefined. diff --git a/db/db_impl/db_impl_open.cc b/db/db_impl/db_impl_open.cc index 91ef84266..a9b42d62a 100644 --- a/db/db_impl/db_impl_open.cc +++ b/db/db_impl/db_impl_open.cc @@ -1453,7 +1453,7 @@ Status DBImpl::RecoverLogFiles(const std::vector& wal_numbers, recovery_ctx->UpdateVersionEdits(cfd, iter->second); } - if (flushed) { + if (flushed || !data_seen) { VersionEdit wal_deletion; if (immutable_db_options_.track_and_verify_wals_in_manifest) { wal_deletion.DeleteWalsBefore(max_wal_number + 1); diff --git a/db/db_wal_test.cc b/db/db_wal_test.cc index 705f53f90..fad0f5d09 100644 --- a/db/db_wal_test.cc +++ b/db/db_wal_test.cc @@ -2399,6 +2399,31 @@ TEST_F(DBWALTest, GetCompressedWalsAfterSync) { Status s = dbfull()->GetSortedWalFiles(wals); ASSERT_OK(s); } + +TEST_F(DBWALTest, EmptyWalReopenTest) { + Options options = CurrentOptions(); + options.env = env_; + CreateAndReopenWithCF({"pikachu"}, options); + + // make sure we can re-open it. + ASSERT_OK(TryReopenWithColumnFamilies({"default", "pikachu"}, options)); + + { + std::vector files; + int num_wal_files = 0; + ASSERT_OK(env_->GetChildren(dbname_, &files)); + for (const auto& file : files) { + uint64_t number = 0; + FileType type = kWalFile; + if (ParseFileName(file, &number, &type) && type == kWalFile) { + num_wal_files++; + } + } + + ASSERT_EQ(num_wal_files, 1); + } +} + } // namespace ROCKSDB_NAMESPACE int main(int argc, char** argv) {