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