Add WAL recovery logging

Reviewers: msantl

Reviewed By: msantl

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1899
This commit is contained in:
Matej Ferencevic 2019-03-04 15:00:15 +01:00
parent 4e7292f2f4
commit 768aeab942

View File

@ -217,9 +217,10 @@ std::vector<fs::path> GetWalFiles(const fs::path &wal_dir) {
return wal_files; return wal_files;
} }
bool ApplyOverDeltas( bool ApplyOverDeltas(const std::vector<fs::path> &wal_files,
const std::vector<fs::path> &wal_files, tx::TransactionId first_to_recover, tx::TransactionId first_to_recover,
const std::function<void(const database::StateDelta &)> &f) { const std::function<void(const database::StateDelta &)> &f,
bool report_to_user) {
for (auto &wal_file : wal_files) { for (auto &wal_file : wal_files) {
auto wal_file_max_tx_id = TransactionIdFromWalFilename(wal_file.filename()); auto wal_file_max_tx_id = TransactionIdFromWalFilename(wal_file.filename());
if (!wal_file_max_tx_id || *wal_file_max_tx_id < first_to_recover) continue; if (!wal_file_max_tx_id || *wal_file_max_tx_id < first_to_recover) continue;
@ -243,6 +244,8 @@ bool ApplyOverDeltas(
if (!delta) break; if (!delta) break;
f(*delta); f(*delta);
} }
LOG_IF(INFO, report_to_user) << "Applied WAL deltas from: " << wal_file;
} }
return true; return true;
@ -263,12 +266,14 @@ std::vector<tx::TransactionId> ReadWalRecoverableTransactions(
std::unordered_set<tx::TransactionId> committed_set; std::unordered_set<tx::TransactionId> committed_set;
auto first_to_recover = FirstWalTxToRecover(recovery_data); auto first_to_recover = FirstWalTxToRecover(recovery_data);
ApplyOverDeltas( ApplyOverDeltas(
wal_files, first_to_recover, [&](const database::StateDelta &delta) { wal_files, first_to_recover,
[&](const database::StateDelta &delta) {
if (delta.transaction_id >= first_to_recover && if (delta.transaction_id >= first_to_recover &&
delta.type == database::StateDelta::Type::TRANSACTION_COMMIT) { delta.type == database::StateDelta::Type::TRANSACTION_COMMIT) {
committed_set.insert(delta.transaction_id); committed_set.insert(delta.transaction_id);
} }
}); },
false);
std::vector<tx::TransactionId> committed_tx_ids(committed_set.size()); std::vector<tx::TransactionId> committed_tx_ids(committed_set.size());
for (auto id : committed_set) committed_tx_ids.push_back(id); for (auto id : committed_set) committed_tx_ids.push_back(id);
@ -446,7 +451,8 @@ void RecoverWal(const fs::path &durability_dir, database::GraphDb *db,
default: default:
transactions->Apply(delta); transactions->Apply(delta);
} }
}); },
true);
// TODO when implementing proper error handling return one of the following: // TODO when implementing proper error handling return one of the following:
// - WAL fully recovered // - WAL fully recovered