Skip to content

Commit

Permalink
fixed llfs crash-recovery test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhaskar Bora committed Jan 15, 2025
1 parent 4b68e88 commit 34e1b71
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/llfs/page_recycler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ auto PageRecycler::metrics_export() -> MetricsExported&
static MetricsExported& metrics_ = [&]() -> MetricsExported& {
static MetricsExported metrics_;

LOG(INFO) << "Registering PageRecycler metrics...";
LLFS_VLOG(1) << "Registering PageRecycler metrics...";
const auto metric_name = [](std::string_view property) {
return batt::to_string("PageRecycler_", property);
};
Expand Down Expand Up @@ -335,7 +335,7 @@ StatusOr<slot_offset_type> PageRecycler::recycle_pages(
return this->wal_device_->slot_range(LogReadMode::kDurable).upper_bound;
}

// Check to see if we have already seen this or newer request.
// Check to see if we have already seen this or any newer request.
//
if (this->largest_offset_as_unique_identifier_ >= offset_as_unique_identifier) {
this->metrics_export().page_id_deletion_reissue.fetch_add(1);
Expand Down
28 changes: 25 additions & 3 deletions src/llfs/page_recycler.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ class FakePageDeleter : public PageDeleter
// Recursively recycle any newly dead pages. If we try to recycle the same page multiple
// times, that is OK, since PageIds are never reused.
//
result = this->test_->recycler_->recycle_pages(as_slice(dead_pages), caller_slot, //
std::lock_guard lock(this->recycle_pages_mutex_);
result = this->test_->recycler_->recycle_pages(as_slice(dead_pages),
this->get_and_incr_unique_offset(), //
&recycle_grant, depth + 1);
BATT_REQUIRE_OK(result);

Expand Down Expand Up @@ -412,10 +414,28 @@ class FakePageDeleter : public PageDeleter
this->recursive_recycle_events_.push(failure).IgnoreError();
}

slot_offset_type get_and_incr_unique_offset()
{
return this->unique_offset_++;
}

void lock_mutex()
{
recycle_pages_mutex_.lock();
}

void unlock_mutex()
{
recycle_pages_mutex_.unlock();
}

PageRecyclerTest* test_;
std::unordered_map<boost::uuids::uuid, slot_offset_type, boost::hash<boost::uuids::uuid>>
current_slot_;
batt::Queue<StatusOr<slot_offset_type>> recursive_recycle_events_;

slot_offset_type unique_offset_{1};
std::mutex recycle_pages_mutex_;
};

TEST_F(PageRecyclerTest, CrashRecovery)
Expand All @@ -435,7 +455,7 @@ TEST_F(PageRecyclerTest, CrashRecovery)

void PageRecyclerTest::run_crash_recovery_test()
{
const usize fake_page_count = 256;
const usize fake_page_count = 190;
const u32 max_branching_factor = 8;

const auto options = llfs::PageRecyclerOptions{} //
Expand Down Expand Up @@ -500,7 +520,9 @@ void PageRecyclerTest::run_crash_recovery_test()
const std::array<PageId, 1> to_recycle = {root_id};

BATT_DEBUG_INFO("Test - recycle_pages");
StatusOr<slot_offset_type> recycle_status = recycler.recycle_pages(to_recycle, 0);
std::lock_guard lock(fake_deleter.recycle_pages_mutex_);
StatusOr<slot_offset_type> recycle_status =
recycler.recycle_pages(to_recycle, fake_deleter.get_and_incr_unique_offset());
if (!recycle_status.ok()) {
failed = true;
break;
Expand Down

0 comments on commit 34e1b71

Please sign in to comment.