Skip to content

Commit

Permalink
dbg
Browse files Browse the repository at this point in the history
  • Loading branch information
hx235 committed Dec 25, 2024
1 parent e241420 commit 86174fb
Showing 1 changed file with 51 additions and 19 deletions.
70 changes: 51 additions & 19 deletions db/db_wal_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<WritableFile> 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);

Expand Down Expand Up @@ -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<WritableFile> 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"));
Expand Down

0 comments on commit 86174fb

Please sign in to comment.