diff --git a/db/db_wal_test.cc b/db/db_wal_test.cc index 2e196446e3ad..7ef1011dbf9a 100644 --- a/db/db_wal_test.cc +++ b/db/db_wal_test.cc @@ -1865,20 +1865,36 @@ TEST_F(DBWALTest, TrackAndVerifyWALsRecycleWAL) { // Recycle the first WAL ASSERT_OK(Put("key1", "old_value")); - - // Create WAL hole - VectorWalPtr log_files; - ASSERT_OK(db_->GetSortedWalFiles(log_files)); - ASSERT_GE(log_files.size(), 1); - ASSERT_OK(test::TruncateFile( - options.env, LogFileName(dbname_, log_files.back()->LogNumber()), - 0 /* new_length */)); - // Recycle the second WAL ASSERT_OK(dbfull()->TEST_SwitchWAL()); ASSERT_OK(Put("key1", "new_value")); - Status s = TryReopen(options); + // // Create WAL hole + // VectorWalPtr log_files; + // ASSERT_OK(db_->GetSortedWalFiles(log_files)); + // ASSERT_EQ(log_files.size(), 2); + // // Drop `Put("key1", "old_value")` in WAL + // ASSERT_OK(test::TruncateFile( + // options.env, LogFileName(dbname_, log_files.front()->LogNumber()), + // 0 /* new_length */)); + + VectorWalPtr log_files; + ASSERT_OK(db_->GetSortedWalFiles(log_files)); + ASSERT_GE(log_files.size(), 2); + std::string log_name = LogFileName(dbname_, log_files.front()->LogNumber()); + Close(); + std::unique_ptr first_log; + Status truncate_status = + options.env->ReopenWritableFile(log_name, &first_log, EnvOptions()); + if (truncate_status.ok()) { + truncate_status = first_log->Truncate(0); + } + if (truncate_status.ok()) { + truncate_status = first_log->Close(); + } + assert(truncate_status.ok()); + + Status s = DB::Open(options, dbname_, &db_); ASSERT_OK(s); @@ -1919,19 +1935,35 @@ TEST_P(DBWALTrackAndVerifyWALsWithParamsTest, Basic) { &sleeping_task, Env::Priority::HIGH); ASSERT_OK(Put("key1", "old_value")); + ASSERT_OK(dbfull()->TEST_SwitchWAL()); + ASSERT_OK(Put("key1", "new_value")); + + // // Create WAL hole + // VectorWalPtr log_files; + // ASSERT_OK(db_->GetSortedWalFiles(log_files)); + // ASSERT_EQ(log_files.size(), 2); + // // Drop `Put("key1", "old_value")` in WAL + // ASSERT_OK(test::TruncateFile( + // options.env, LogFileName(dbname_, log_files.front()->LogNumber()), + // 0 /* new_length */)); - // Create WAL hole VectorWalPtr log_files; ASSERT_OK(db_->GetSortedWalFiles(log_files)); - ASSERT_EQ(log_files.size(), 1); - ASSERT_OK(test::TruncateFile( - options.env, LogFileName(dbname_, log_files.back()->LogNumber()), - 0 /* new_length */)); - - ASSERT_OK(dbfull()->TEST_SwitchWAL()); - ASSERT_OK(Put("key1", "new_value")); + ASSERT_GE(log_files.size(), 2); + std::string log_name = LogFileName(dbname_, log_files.front()->LogNumber()); + Close(); + std::unique_ptr first_log; + Status truncate_status = + options.env->ReopenWritableFile(log_name, &first_log, EnvOptions()); + if (truncate_status.ok()) { + truncate_status = first_log->Truncate(0); + } + if (truncate_status.ok()) { + truncate_status = first_log->Close(); + } + assert(truncate_status.ok()); - Status s = TryReopen(options); + Status s = DB::Open(options, dbname_, &db_); if (options.wal_recovery_mode == WALRecoveryMode::kPointInTimeRecovery) { ASSERT_OK(s); ASSERT_EQ("NOT_FOUND", Get("key1"));