Update snapshot naming
Summary: Snapshots should have the transaction from which they were created because we need this info for recovery later on. Otherwise we wouldn't be able to tell the workers from which snapshots to recover. The whole cluster should be recovered from the same transaction snapshot. Reviewers: msantl Reviewed By: msantl Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1338
This commit is contained in:
parent
5f53a7a759
commit
a36753cf27
@ -69,11 +69,13 @@ std::experimental::optional<tx::transaction_id_t> TransactionIdFromWalFilename(
|
||||
}
|
||||
}
|
||||
|
||||
fs::path MakeSnapshotPath(const fs::path &durability_dir, const int worker_id) {
|
||||
fs::path MakeSnapshotPath(const fs::path &durability_dir, const int worker_id,
|
||||
tx::transaction_id_t tx_id) {
|
||||
std::string date_str =
|
||||
Timestamp(Timestamp::Now())
|
||||
.ToString("{:04d}_{:02d}_{:02d}__{:02d}_{:02d}_{:02d}_{:05d}");
|
||||
auto file_name = date_str + "_worker_" + std::to_string(worker_id);
|
||||
auto file_name = date_str + "_worker_" + std::to_string(worker_id) + "_tx_" +
|
||||
std::to_string(tx_id);
|
||||
return durability_dir / kSnapshotDir / file_name;
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,11 @@ std::experimental::optional<tx::transaction_id_t> TransactionIdFromWalFilename(
|
||||
const std::string &name);
|
||||
|
||||
/** Generates a path for a DB snapshot in the given folder in a well-defined
|
||||
* sortable format with worker id appended to the file name. */
|
||||
* sortable format with worker id and transaction from which the snapshot is
|
||||
* created appended to the file name. */
|
||||
std::experimental::filesystem::path MakeSnapshotPath(
|
||||
const std::experimental::filesystem::path &durability_dir, int worker_id);
|
||||
const std::experimental::filesystem::path &durability_dir, int worker_id,
|
||||
tx::transaction_id_t tx_id);
|
||||
|
||||
/// Generates a file path for a write-ahead log file of a specified worker. If
|
||||
/// given a transaction ID the file name will contain it. Otherwise the file
|
||||
|
@ -119,10 +119,11 @@ void RemoveOldWals(const fs::path &wal_dir,
|
||||
|
||||
bool MakeSnapshot(database::GraphDb &db, const fs::path &durability_dir,
|
||||
const int snapshot_max_retained) {
|
||||
if (!EnsureDir(durability_dir / kSnapshotDir)) return false;
|
||||
const auto snapshot_file = MakeSnapshotPath(durability_dir, db.WorkerId());
|
||||
if (fs::exists(snapshot_file)) return false;
|
||||
database::GraphDbAccessor dba(db);
|
||||
if (!EnsureDir(durability_dir / kSnapshotDir)) return false;
|
||||
const auto snapshot_file =
|
||||
MakeSnapshotPath(durability_dir, db.WorkerId(), dba.transaction_id());
|
||||
if (fs::exists(snapshot_file)) return false;
|
||||
if (Encode(snapshot_file, db, dba)) {
|
||||
RemoveOldSnapshots(durability_dir / kSnapshotDir, snapshot_max_retained);
|
||||
RemoveOldWals(durability_dir / kWalDir, dba.transaction());
|
||||
|
@ -119,8 +119,10 @@ void WriteToSnapshot(GraphState &state, const std::string &path) {
|
||||
LOG(ERROR) << "Unable to create durability directory!";
|
||||
exit(0);
|
||||
}
|
||||
// Pretend like this is coming from transaction numbered 1 - this is hack
|
||||
// TODO(dgleich): Change this to something more reasonable
|
||||
const auto snapshot_file =
|
||||
durability::MakeSnapshotPath(durability_dir, worker_id);
|
||||
durability::MakeSnapshotPath(durability_dir, worker_id, 1);
|
||||
|
||||
SnapshotWriter writer(snapshot_file, worker_id,
|
||||
state.NumNodesOnWorker(worker_id),
|
||||
|
@ -470,7 +470,9 @@ std::string GetOutputPath() {
|
||||
LOG(FATAL) << error.what();
|
||||
}
|
||||
int worker_id = 0;
|
||||
return std::string(durability::MakeSnapshotPath(durability_dir, worker_id));
|
||||
// TODO(dgleich): Remove this transaction id hack
|
||||
return std::string(
|
||||
durability::MakeSnapshotPath(durability_dir, worker_id, 1));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
Loading…
Reference in New Issue
Block a user