Skip to content

Commit

Permalink
Merge branch 'dev-umegane-1057' into dev-umegane-1034
Browse files Browse the repository at this point in the history
  • Loading branch information
umegane committed Dec 18, 2024
2 parents 6d8a9f5 + 2a16ed6 commit ee64e95
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/limestone/datastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,25 +264,31 @@ void datastore::update_min_epoch_id(bool from_switch_epoch) { // NOLINT(readabi
if (from_switch_epoch && (to_be_epoch > static_cast<std::uint64_t>(max_finished_epoch))) {
to_be_epoch = static_cast<std::uint64_t>(max_finished_epoch);
}

TRACE << "update epoch file part start with to_be_epoch = " << to_be_epoch;
auto old_epoch_id = epoch_id_to_be_recorded_.load();
while (true) {
if (old_epoch_id >= to_be_epoch) {
break;
}
if (epoch_id_to_be_recorded_.compare_exchange_strong(old_epoch_id, to_be_epoch)) {
TRACE << "epoch_id_to_be_recorded_ updated to " << to_be_epoch;
std::lock_guard<std::mutex> lock(mtx_epoch_file_);
write_epoch_to_file(static_cast<epoch_id_type>(to_be_epoch));
epoch_id_record_finished_.store(epoch_id_to_be_recorded_.load());
TRACE << "epoch_id_record_finished_ updated to " << to_be_epoch;
break;
}
}
if (to_be_epoch > epoch_id_record_finished_.load()) {
TRACE << "skipping persistent callback part, to_be_epoch = " << to_be_epoch << ", epoch_id_record_finished_ = " << epoch_id_record_finished_.load();
TRACE_END;
return;
}

// update informed_epoch_
to_be_epoch = upper_limit;
TRACE << "persistent callback part start with to_be_epoch =" << to_be_epoch;
// In `informed_epoch_`, the update restriction based on the `from_switch_epoch` condition is intentionally omitted.
// Due to the interface specifications of Shirakami, it is necessary to advance the epoch even if the log channel
// is not updated. This behavior differs from `recorded_epoch_` and should be maintained as such.
Expand All @@ -292,6 +298,7 @@ void datastore::update_min_epoch_id(bool from_switch_epoch) { // NOLINT(readabi
break;
}
if (epoch_id_informed_.compare_exchange_strong(old_epoch_id, to_be_epoch)) {
TRACE << "epoch_id_informed_ updated to " << to_be_epoch;
{
std::lock_guard<std::mutex> lock(mtx_epoch_persistent_callback_);
if (to_be_epoch < epoch_id_informed_.load()) {
Expand Down Expand Up @@ -475,7 +482,7 @@ rotation_result datastore::rotate_log_files() {
}
TRACE << "epoch_id = " << epoch_id;
{
on_wait1();
on_wait1(); // for testing
// Wait until epoch_id_informed_ is less than rotated_epoch_id to ensure safe rotation.
std::unique_lock<std::mutex> ul(informed_mutex);
while (epoch_id_informed_.load() < epoch_id) {
Expand Down

0 comments on commit ee64e95

Please sign in to comment.