Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
DEMO
Loading...
Searching...
No Matches
signet::forge::WalReader Class Reference

Sequential WAL file reader for crash recovery and replay. More...

#include <wal.hpp>

Public Types

enum class  ValidationMode : uint8_t { BestEffort = 0 , Strict = 1 }
 

Public Member Functions

 WalReader (const WalReader &)=delete
 
WalReaderoperator= (const WalReader &)=delete
 
 WalReader (WalReader &&o) noexcept
 
WalReaderoperator= (WalReader &&)=delete
 
 ~WalReader ()
 
expected< std::optional< WalEntry > > next ()
 Read the next WAL entry from the file.
 
expected< std::vector< WalEntry > > read_all ()
 Read all valid entries from the current position to end-of-valid-data.
 
int64_t last_seq () const noexcept
 Sequence number of the last successfully read record (-1 if none).
 
int64_t count () const noexcept
 Number of records successfully read so far.
 
size_t offset () const noexcept
 Current byte offset in the file (past the last read record).
 
void close ()
 Close the underlying file handle.
 

Static Public Member Functions

static expected< WalReaderopen (const std::string &path, ValidationMode mode=ValidationMode::BestEffort)
 Open a WAL file for sequential reading.
 

Detailed Description

Sequential WAL file reader for crash recovery and replay.

Reads records forward from the file header, validating magic bytes and CRC-32 integrity. Stops gracefully on truncation, corruption, or EOF (returns nullopt rather than Error for soft failures).

Non-copyable, move-constructible. Use WalReader::open() to create.

See also
WalWriter, WalEntry

Definition at line 572 of file wal.hpp.

Member Enumeration Documentation

◆ ValidationMode

enum class signet::forge::WalReader::ValidationMode : uint8_t
strong
Enumerator
BestEffort 
Strict 

Definition at line 574 of file wal.hpp.

Constructor & Destructor Documentation

◆ WalReader() [1/2]

signet::forge::WalReader::WalReader ( const WalReader )
delete

◆ WalReader() [2/2]

signet::forge::WalReader::WalReader ( WalReader &&  o)
inlinenoexcept

Definition at line 581 of file wal.hpp.

◆ ~WalReader()

signet::forge::WalReader::~WalReader ( )
inline

Definition at line 587 of file wal.hpp.

Member Function Documentation

◆ close()

void signet::forge::WalReader::close ( )
inline

Close the underlying file handle.

Definition at line 732 of file wal.hpp.

◆ count()

int64_t signet::forge::WalReader::count ( ) const
inlinenoexcept

Number of records successfully read so far.

Definition at line 727 of file wal.hpp.

◆ last_seq()

int64_t signet::forge::WalReader::last_seq ( ) const
inlinenoexcept

Sequence number of the last successfully read record (-1 if none).

Definition at line 725 of file wal.hpp.

◆ next()

expected< std::optional< WalEntry > > signet::forge::WalReader::next ( )
inline

Read the next WAL entry from the file.

Returns nullopt on clean EOF, truncation, bad magic, oversized records, or CRC mismatch (all treated as soft end-of-valid-data). Returns an Error only on hard I/O failures (fread sets errno).

Returns
The next WalEntry, nullopt on soft stop, or Error on hard I/O failure.

Definition at line 626 of file wal.hpp.

◆ offset()

size_t signet::forge::WalReader::offset ( ) const
inlinenoexcept

Current byte offset in the file (past the last read record).

Definition at line 729 of file wal.hpp.

◆ open()

static expected< WalReader > signet::forge::WalReader::open ( const std::string &  path,
ValidationMode  mode = ValidationMode::BestEffort 
)
inlinestatic

Open a WAL file for sequential reading.

Validates the 16-byte file header magic. After opening, call next() or read_all() to iterate records.

Parameters
pathFilesystem path to the WAL file.
Returns
WalReader on success, Error if the file cannot be opened or has an invalid header.

Definition at line 597 of file wal.hpp.

◆ operator=() [1/2]

WalReader & signet::forge::WalReader::operator= ( const WalReader )
delete

◆ operator=() [2/2]

WalReader & signet::forge::WalReader::operator= ( WalReader &&  )
delete

◆ read_all()

expected< std::vector< WalEntry > > signet::forge::WalReader::read_all ( )
inline

Read all valid entries from the current position to end-of-valid-data.

Stops at the first corrupt, truncated, or EOF record. Useful for full crash-recovery replay.

Returns
Vector of all valid WalEntry records, or Error on hard I/O failure.

Definition at line 713 of file wal.hpp.


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