forked from llnl/metall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnapshot.cpp
More file actions
58 lines (48 loc) · 2.06 KB
/
Copy pathsnapshot.cpp
File metadata and controls
58 lines (48 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2019 Lawrence Livermore National Security, LLC and other Metall
// Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
#include <string>
#include <metall/metall.hpp>
int main() {
const std::string master_path("/tmp/dir_path");
const std::string snapshot_dir_prefix("/tmp/snapshot-");
const std::string snapshot_name0 = snapshot_dir_prefix + "ver0";
const std::string snapshot_name1 = snapshot_dir_prefix + "ver1";
{
// Create the master data
metall::manager manager(metall::create_only, master_path.c_str());
int *a = manager.construct<int>(metall::unique_instance)(0);
// Take a snapshot before updating to '1'
manager.snapshot(snapshot_name0.c_str());
*a = 1;
// Take a snapshot before updating to '2'
manager.snapshot(snapshot_name1.c_str());
*a = 2;
}
// Open snapshot 0 if it is consistent, i.e., it was closed properly.
if (metall::manager::consistent(snapshot_name0.c_str())) {
metall::manager manager(metall::open_read_only, snapshot_name0.c_str());
int *a = manager.find<int>(metall::unique_instance).first;
std::cout << *a << std::endl; // Print 0
} else {
std::cerr << snapshot_name0 << " is inconsistent" << std::endl;
}
// Open snapshot 1 if it is consistent, i.e., it was closed properly.
if (metall::manager::consistent(snapshot_name1.c_str())) {
metall::manager manager(metall::open_read_only, snapshot_name1.c_str());
int *a = manager.find<int>(metall::unique_instance).first;
std::cout << *a << std::endl; // Print 1
} else {
std::cerr << snapshot_name1 << " is inconsistent" << std::endl;
}
// Open the master data if it is consistent, i.e., it was closed properly.
if (metall::manager::consistent(master_path.c_str())) {
metall::manager manager(metall::open_read_only, master_path.c_str());
int *a = manager.find<int>(metall::unique_instance).first;
std::cout << *a << std::endl; // Print 2
} else {
std::cerr << master_path << " is inconsistent" << std::endl;
}
return 0;
}