Fenix @develop
 
Loading...
Searching...
No Matches
snapshot.hpp
1#ifndef __FENIX_DATA_SNAPSHOT_HPP__
2#define __FENIX_DATA_SNAPSHOT_HPP__
3
4#include <mpi.h>
5#include <optional>
6#include "fenix/data/util/buffer.hpp"
7#include "fenix/data/util/data_ref.hpp"
8#include "fenix/data/util/serializer.hpp"
9#include "fenix/data/subset.hpp"
10#include "fenix/mpixx/group.hpp"
11
12namespace fenix::data {
13
14// DataSnapshot provides common storage and operations for checkpoint entries
15// used by data recovery policies.
16// Derived classes can extend with policy-specific storage and operations
17// (e.g., partner buffers for redundancy in IMR policies).
19 protected:
24
25 mpixx::Group cohort_;
26
27 public:
28 int cohort_rank = -1;
29
30 std::vector<DataSubset> protected_subsets;
32 std::vector<DataSubset>
34
35 DataSnapshot(int elm_size, int max_count);
36 virtual ~DataSnapshot();
37
38 DataSnapshot(DataSnapshot&&) = default;
39 DataSnapshot& operator=(DataSnapshot&&) = default;
40
41 // DataSnapshots are move-only
42 DataSnapshot(const DataSnapshot&) = delete;
43 DataSnapshot& operator=(const DataSnapshot&) = delete;
44
45 // Clear the buffer and region, reset timestamp to -2, cohort to
46 // MPI_GROUP_NULL.
47 void reset();
48
49 // Called when snapshot is first staged to - sets cohort and allocates
50 // storage for tracking subsets per cohort partner
51 virtual void init_cohort(MPI_Comm cohort_comm);
52
53 // Called during repair - replaces cohort if already initialized, or
54 // initializes if not
55 virtual void reinit_cohort(MPI_Comm cohort_comm);
56
57 // Create a serializer that writes to this snapshot's buffer from the source
58 util::Serializer create_serializer(
59 const util::DataRef& source, std::optional<SerializeFunc>& sf,
60 const DataSubset& subset
61 );
62
63 // Create a deserializer that reads from this snapshot's buffer to destination
64 util::Serializer create_deserializer(
65 const util::DataRef& dst, std::optional<SerializeFunc>& sf,
66 const DataSubset& subset
67 );
68
69 char* data() { return buf_.data(); }
70 int size() const { return buf_.size(); }
71 void resize(int size) { buf_.resize(size); }
72
73 // Merges the given subset into the snapshot's region and resizes the
74 // buffer if needed to accommodate the expanded region.
75 void add_and_fit(const DataSubset& subset);
76
77 // -2 == uninitialized, -1 for staging, >= 0 committed
78 int timestamp() const { return timestamp_; }
79 void set_timestamp(int ts) { timestamp_ = ts; }
80
81 const DataSubset& staged_subset() const {
83 }
84 DataSubset& staged_subset() { return staged_subsets[cohort_rank]; }
85
86 const DataSubset& protected_subset() const {
88 }
89 DataSubset& protected_subset() { return protected_subsets[cohort_rank]; }
90
91 util::DataBuffer& buf() { return buf_; }
92
93 int elm_size() const { return elm_size_; }
94 void set_elm_size(int size) { elm_size_ = size; }
95 int elm_max_count() const { return elm_max_count_; }
96};
97
98// Heterogeneous comparator for snapshot timestamp ordering
99// Enables direct lookup by timestamp: commit_snapshots_.find(timestamp)
101 using is_transparent = void; // Enables heterogeneous lookup
102
103 bool operator()(
104 const std::unique_ptr<DataSnapshot>& a,
105 const std::unique_ptr<DataSnapshot>& b
106 ) const {
107 return a->timestamp() < b->timestamp();
108 }
109
110 bool operator()(const std::unique_ptr<DataSnapshot>& a, int timestamp) const {
111 return a->timestamp() < timestamp;
112 }
113
114 bool operator()(int timestamp, const std::unique_ptr<DataSnapshot>& a) const {
115 return timestamp < a->timestamp();
116 }
117};
118
119} // namespace fenix::data
120
121#endif // __FENIX_DATA_SNAPSHOT_HPP__
Definition snapshot.hpp:18
util::DataBuffer buf_
Primary checkpoint data buffer.
Definition snapshot.hpp:20
int cohort_rank
This rank's index within the cohort.
Definition snapshot.hpp:28
int elm_size_
Size of each element in bytes.
Definition snapshot.hpp:22
std::vector< DataSubset > protected_subsets
Definition snapshot.hpp:30
int timestamp_
Snapshot version/commit timestamp.
Definition snapshot.hpp:21
int elm_max_count_
Maximum number of elements.
Definition snapshot.hpp:23
std::vector< DataSubset > staged_subsets
Subsets staged by each cohort member (including self)
Definition snapshot.hpp:33
Definition buffer.hpp:68
Definition data_ref.hpp:50
Definition serializer.hpp:14
Definition group.hpp:21
Definition subset.hpp:152