diff --git a/db/db_impl.cc b/db/db_impl.cc index ccc8391ec..7e101fb7c 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1722,7 +1722,7 @@ Status DBImpl::RecoverLogFiles(const std::vector& log_numbers, // recovered and should be ignored on next reincarnation. // Since we already recovered max_log_number, we want all logs // with numbers `<= max_log_number` (includes this one) to be ignored - if (flushed) { + if (flushed || cfd->mem()->GetFirstSequenceNumber() == 0) { edit->SetLogNumber(max_log_number + 1); } // we must mark the next log number as used, even though it's diff --git a/db/db_wal_test.cc b/db/db_wal_test.cc index 34d780511..10520b774 100644 --- a/db/db_wal_test.cc +++ b/db/db_wal_test.cc @@ -305,6 +305,31 @@ TEST_F(DBWALTest, GetSortedWalFiles) { } while (ChangeOptions()); } +TEST_F(DBWALTest, RecoveryWithLogDataForSomeCFs) { + // Test for regression of WAL cleanup missing files that don't contain data + // for every column family. + do { + CreateAndReopenWithCF({"pikachu"}, CurrentOptions()); + ASSERT_OK(Put(1, "foo", "v1")); + ASSERT_OK(Put(1, "foo", "v2")); + std::array earliest_log_nums; + for (int i = 0; i < 2; ++i) { + if (i > 0) { + ReopenWithColumnFamilies({"default", "pikachu"}, CurrentOptions()); + } + VectorLogPtr log_files; + ASSERT_OK(dbfull()->GetSortedWalFiles(log_files)); + if (log_files.size() > 0) { + earliest_log_nums[i] = log_files[0]->LogNumber(); + } else { + earliest_log_nums[i] = port::kMaxUint64; + } + } + // Check at least the first WAL was cleaned up during the recovery. + ASSERT_LT(earliest_log_nums[0], earliest_log_nums[1]); + } while (ChangeOptions()); +} + TEST_F(DBWALTest, RecoverWithLargeLog) { do { {