33#include "id_predicates.hpp"
36#include <nonstd/expected.hpp>
44namespace ngen{
namespace serialization{
50using nonstd::expected;
51using nonstd::make_unexpected;
99 -> expected<void, BackendError> = 0;
108 -> expected<void, BackendError> = 0;
125 -> expected<Record, BackendError> = 0;
132 -> expected<Record, BackendError> = 0;
138 [[nodiscard]]
virtual auto
140 int64_t simulation_timestamp)
141 -> expected<Record, BackendError> = 0;
148 [[nodiscard]]
virtual auto close() -> expected<void, BackendError> {
160 [[nodiscard]]
virtual auto
161 writer(std::chrono::system_clock::time_point epoch,
198 -> expected<void, std::vector<BackendError>> = 0;
208 template <
typename F>
209 [[nodiscard]]
auto with_writer(std::chrono::system_clock::time_point epoch,
211 -> expected<void, BackendError>
213 auto wo =
writer(epoch, durability);
214 if (!wo)
return make_unexpected(std::move(wo.error()));
215 std::forward<F>(fn)(*wo.value());
216 return wo.value()->commit();
223 template <
typename F>
225 -> expected<void, BackendError>
227 auto ro =
reader(std::move(in_scope));
228 if (!ro)
return make_unexpected(std::move(ro.error()));
229 std::forward<F>(fn)(*ro.value());
230 return ro.value()->close();
A read handle for one restore session.
Definition record_backend.hpp:117
virtual ~Reader()=default
virtual auto close() -> expected< void, BackendError >
Optional explicit close.
Definition record_backend.hpp:148
virtual auto find_at_step(const std::string &id, int64_t time_step) -> expected< Record, BackendError >=0
Return the record for id at the given simulation step.
virtual auto find_at_simulation_timestamp(const std::string &id, int64_t simulation_timestamp) -> expected< Record, BackendError >=0
Return the record for id at the given simulation timestamp (seconds since Unix epoch).
virtual auto find_latest(const std::string &id) -> expected< Record, BackendError >=0
Return the latest record for id within this Reader's scope.
A writer for one checkpoint event.
Definition record_backend.hpp:88
virtual auto write(const RecordView &rv) -> expected< void, BackendError >=0
Append a record to this checkpoint event.
virtual auto commit() -> expected< void, BackendError >=0
Commit the event: flush pending writes, make them durable (under Durability::strict),...
virtual ~Writer()=default
Abstract storage interface for Records.
Definition record_backend.hpp:83
virtual auto writer(std::chrono::system_clock::time_point epoch, Durability durability) -> expected< std::unique_ptr< Writer >, BackendError >=0
Construct a Writer for one checkpoint event.
auto with_reader(IdPredicate in_scope, F &&fn) -> expected< void, BackendError >
Run fn inside a scoped Reader; calls close() automatically on success.
Definition record_backend.hpp:224
auto with_writer(std::chrono::system_clock::time_point epoch, Durability durability, F &&fn) -> expected< void, BackendError >
Run fn inside a scoped Writer; calls commit() automatically on success.
Definition record_backend.hpp:209
virtual auto reader(IdPredicate in_scope={}) -> expected< std::unique_ptr< Reader >, BackendError >=0
Construct a Reader scoped to records whose id satisfies in_scope.
virtual auto finalize() -> expected< void, std::vector< BackendError > >=0
Lifecycle hook for cross-event cleanup: close process-level open handles, drain async queues,...
virtual ~RecordBackend()=default
std::function< bool(const std::string &id)> IdPredicate
Eligibility predicate over a SerializationRecord's id string.
Definition id_predicates.hpp:56
Durability
Save-time durability requirement.
Definition record_backend.hpp:59
Definition DomainLayer.hpp:13
Categorized error carried on every abstract-backend method's expected<> error arm.
Definition record_backend.hpp:70
Kind kind
Definition record_backend.hpp:72
BackendError(Kind k, std::string m)
Definition record_backend.hpp:76
Kind
Definition record_backend.hpp:71
std::string message
Definition record_backend.hpp:73
Definition record.hpp:151