NGen
Loading...
Searching...
No Matches
ngen::serialization::RecordBackend Class Referenceabstract

Abstract storage interface for Records. More...

#include <record_backend.hpp>

+ Inheritance diagram for ngen::serialization::RecordBackend:
+ Collaboration diagram for ngen::serialization::RecordBackend:

Classes

class  Reader
 A read handle for one restore session. More...
 
class  Writer
 A writer for one checkpoint event. More...
 

Public Member Functions

virtual ~RecordBackend ()=default
 
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.
 
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, surface deferred errors.
 
template<typename F >
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.
 
template<typename F >
auto with_reader (IdPredicate in_scope, F &&fn) -> expected< void, BackendError >
 Run fn inside a scoped Reader; calls close() automatically on success.
 

Detailed Description

Abstract storage interface for Records.

See the README for the cross-cutting rules every backend must satisfy; this header documents the per-method API contract.

Constructor & Destructor Documentation

◆ ~RecordBackend()

virtual ngen::serialization::RecordBackend::~RecordBackend ( )
virtualdefault

Member Function Documentation

◆ finalize()

virtual auto ngen::serialization::RecordBackend::finalize ( ) -> expected< void, std::vector< BackendError > >
nodiscardpure virtual

Lifecycle hook for cross-event cleanup: close process-level open handles, drain async queues, surface deferred errors.

Engine calls this at MPI synchronization points or before shutdown.

Error arm carries the vector of every BackendError accumulated since the last finalize() call — typically those deferred under Durability::relaxed from earlier write()/commit() calls, or any errors that surfaced during finalize itself. Each entry keeps its own structured Kind and message, so callers can branch per-error:

if (auto r = backend->finalize(); !r) {
    for (const auto& e : r.error()) {
        switch (e.kind) {
            case BackendError::Kind::IOError:   ...
            case BackendError::Kind::Corrupted: ...
            case BackendError::Kind::NotFound:  ...
        }
    }
}

An empty deferred-error set is success — the success arm is returned, not an error arm with an empty vector.

Implemented in ngen::serialization::FileBackend.

◆ reader()

virtual auto ngen::serialization::RecordBackend::reader ( IdPredicate in_scope = {}) -> expected< std::unique_ptr< Reader >, BackendError >
nodiscardpure virtual

Construct a Reader scoped to records whose id satisfies in_scope.

The predicate is both a hint and an enforced scope — out-of-scope ids return Kind::NotFound. An empty predicate means "no scope" — the Reader will find any record.

Implemented in ngen::serialization::FileBackend.

Referenced by with_reader().

◆ with_reader()

template<typename F >
auto ngen::serialization::RecordBackend::with_reader ( IdPredicate in_scope,
F && fn ) -> expected<void, BackendError>
inlinenodiscard

Run fn inside a scoped Reader; calls close() automatically on success.

Exceptions from fn unwind through the Reader destructor and re-throw to the caller.

Template Parameters
Finvocable as void(Reader&).

References reader().

◆ with_writer()

template<typename F >
auto ngen::serialization::RecordBackend::with_writer ( std::chrono::system_clock::time_point epoch,
Durability durability,
F && fn ) -> expected<void, BackendError>
inlinenodiscard

Run fn inside a scoped Writer; calls commit() automatically on success.

Exceptions from fn unwind through the Writer destructor and re-throw to the caller.

Template Parameters
Finvocable as void(Writer&).

References writer().

◆ writer()

virtual auto ngen::serialization::RecordBackend::writer ( std::chrono::system_clock::time_point epoch,
Durability durability ) -> expected< std::unique_ptr< Writer >, BackendError >
nodiscardpure virtual

Construct a Writer for one checkpoint event.

Backends MUST return the error arm when a previous Writer is still alive on the same instance (single-in-flight rule). Callers should prefer with_writer below, which makes the rule a syntactic property of the call site.

Implemented in ngen::serialization::FileBackend.

Referenced by with_writer().


The documentation for this class was generated from the following file: