Skip to content

Commit

Permalink
draft improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
hx235 committed Dec 25, 2024
1 parent a969ced commit fcbca60
Showing 1 changed file with 49 additions and 13 deletions.
62 changes: 49 additions & 13 deletions db/db_wal_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1865,20 +1865,38 @@ TEST_F(DBWALTest, TrackAndVerifyWALsRecycleWAL) {

// Recycle the first WAL
ASSERT_OK(Put("key1", "old_value"));
// Recycle the second WAL
ASSERT_OK(dbfull()->TEST_SwitchWAL());
ASSERT_OK(Put("key1", "new_value"));

// Create WAL hole
VectorWalPtr log_files;
ASSERT_OK(db_->GetSortedWalFiles(log_files));
ASSERT_GE(log_files.size(), 1);
ASSERT_EQ(log_files.size(), 2);
std::string log_name = LogFileName(dbname_, log_files.front()->LogNumber());
Close();
// Drop `Put("key1", "old_value")` in WAL
ASSERT_OK(test::TruncateFile(
options.env, LogFileName(dbname_, log_files.back()->LogNumber()),
options.env, log_name,
0 /* new_length */));

// Recycle the second WAL
ASSERT_OK(dbfull()->TEST_SwitchWAL());
ASSERT_OK(Put("key1", "new_value"));

Status s = TryReopen(options);
// 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 +1937,37 @@ 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(), 1);
ASSERT_EQ(log_files.size(), 2);
std::string log_name = LogFileName(dbname_, log_files.front()->LogNumber());
Close();
// Drop `Put("key1", "old_value")` in WAL
ASSERT_OK(test::TruncateFile(
options.env, LogFileName(dbname_, log_files.back()->LogNumber()),
options.env, log_name,
0 /* new_length */));

ASSERT_OK(dbfull()->TEST_SwitchWAL());
ASSERT_OK(Put("key1", "new_value"));

Status s = TryReopen(options);
// 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_);
if (options.wal_recovery_mode == WALRecoveryMode::kPointInTimeRecovery) {
ASSERT_OK(s);
ASSERT_EQ("NOT_FOUND", Get("key1"));
Expand Down

0 comments on commit fcbca60

Please sign in to comment.