Skip to content

Commit

Permalink
addressed the case where epoch file writing takes a long time
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Nov 27, 2024
1 parent 003f01a commit 4417c00
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/limestone/api/datastore.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class datastore {

epoch_id_type search_max_durable_epock_id() noexcept;

void update_min_epoch_id(bool from_switch_epoch = false);
void update_min_epoch_id(log_channel* caller = nullptr);

void check_after_ready(std::string_view func) const noexcept;

Expand Down
14 changes: 8 additions & 6 deletions src/limestone/datastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ void datastore::switch_epoch(epoch_id_type new_epoch_id) {
}

epoch_id_switched_.store(neid);
update_min_epoch_id(true);
update_min_epoch_id();
} catch (...) {
HANDLE_EXCEPTION_AND_ABORT();
}
}

void datastore::update_min_epoch_id(bool from_switch_epoch) { // NOLINT(readability-function-cognitive-complexity)
void datastore::update_min_epoch_id(log_channel* caller) { // NOLINT(readability-function-cognitive-complexity)
auto upper_limit = epoch_id_switched_.load();
if (upper_limit == 0) {
return; // If epoch_id_switched_ is zero, it means no epoch has been switched, so updating epoch_id_recorded_ and epoch_id_informed_ is unnecessary.
Expand All @@ -177,9 +177,11 @@ void datastore::update_min_epoch_id(bool from_switch_epoch) { // NOLINT(readabi
epoch_id_type max_finished_epoch = 0;

for (const auto& e : log_channels_) {
auto working_epoch = static_cast<epoch_id_type>(e->current_epoch_id_.load());
if ((working_epoch - 1) < upper_limit && working_epoch != UINT64_MAX) {
upper_limit = working_epoch - 1;
if (e.get() != caller) {
auto working_epoch = static_cast<epoch_id_type>(e->current_epoch_id_.load());
if ((working_epoch - 1) < upper_limit && working_epoch != UINT64_MAX) {
upper_limit = working_epoch - 1;
}
}
auto finished_epoch = e->finished_epoch_id_.load();
if (max_finished_epoch < finished_epoch) {
Expand All @@ -189,7 +191,7 @@ void datastore::update_min_epoch_id(bool from_switch_epoch) { // NOLINT(readabi

// update recorded_epoch_
auto to_be_epoch = upper_limit;
if (from_switch_epoch && (to_be_epoch > static_cast<std::uint64_t>(max_finished_epoch))) {
if (!caller && (to_be_epoch > static_cast<std::uint64_t>(max_finished_epoch))) {
to_be_epoch = static_cast<std::uint64_t>(max_finished_epoch);
}
auto old_epoch_id = epoch_id_recorded_.load();
Expand Down
2 changes: 1 addition & 1 deletion src/limestone/log_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ void log_channel::end_session() {
LOG_AND_THROW_IO_EXCEPTION("fsync failed", errno);
}
finished_epoch_id_.store(current_epoch_id_.load());
envelope_.update_min_epoch_id(this);
current_epoch_id_.store(UINT64_MAX);
envelope_.update_min_epoch_id();

if (fclose(strm_) != 0) { // NOLINT(*-owning-memory)
LOG_AND_THROW_IO_EXCEPTION("fclose failed", errno);
Expand Down

0 comments on commit 4417c00

Please sign in to comment.