From 2ac22523ea1d62f5f2129a3a7a75c6cf48d65fd8 Mon Sep 17 00:00:00 2001 From: antoniofilipovic Date: Wed, 28 Feb 2024 10:00:46 +0100 Subject: [PATCH] revert back durability --- src/storage/v2/durability/durability.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/storage/v2/durability/durability.cpp b/src/storage/v2/durability/durability.cpp index 8ff94b92f..6f4857f80 100644 --- a/src/storage/v2/durability/durability.cpp +++ b/src/storage/v2/durability/durability.cpp @@ -418,10 +418,11 @@ std::optional Recovery::RecoverData(std::string *uuid, Replication // We can also set the last timestamp to 0 if last loaded timestamp // is nullopt as this can only happen if the WAL file with seq = 0 // does not contain any deltas and we didn't find any snapshots. + /* if (last_loaded_timestamp) { epoch_history->emplace_back(repl_storage_state.epoch_.id(), *last_loaded_timestamp); } - + */ for (auto &wal_file : wal_files) { if (previous_seq_num && (wal_file.seq_num - *previous_seq_num) > 1) { LOG_FATAL("You are missing a WAL file with the sequence number {}!", *previous_seq_num + 1); @@ -437,6 +438,18 @@ std::optional Recovery::RecoverData(std::string *uuid, Replication recovery_info.last_commit_timestamp = info.last_commit_timestamp; + if (wal_file.epoch_id != repl_storage_state.epoch_.id()) { + // This way we skip WALs finalized only because of role change. + // We can also set the last timestamp to 0 if last loaded timestamp + // is nullopt as this can only happen if the WAL file with seq = 0 + // does not contain any deltas and we didn't find any snapshots. + if (last_loaded_timestamp) { + epoch_history->emplace_back(wal_file.epoch_id, *last_loaded_timestamp); + } + repl_storage_state.epoch_.SetEpoch(std::move(wal_file.epoch_id)); + } + + /* if (recovery_info.next_timestamp != 0) { last_loaded_timestamp.emplace(recovery_info.next_timestamp - 1); } @@ -452,9 +465,14 @@ std::optional Recovery::RecoverData(std::string *uuid, Replication if (last_epoch_bigger_timestamp) { epoch_history->back().second = last_loaded_timestamp.value_or(0); } + */ + } catch (const RecoveryFailure &e) { LOG_FATAL("Couldn't recover WAL deltas from {} because of: {}", wal_file.path, e.what()); } + if (recovery_info.next_timestamp != 0) { + last_loaded_timestamp.emplace(recovery_info.next_timestamp - 1); + } } // The sequence number needs to be recovered even though `LoadWal` didn't // load any deltas from that file.