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

Manages multiple rolling WAL segment files in a directory. More...

#include <wal.hpp>

Public Types

using Options = WalManagerOptions
 Alias for the options struct.
 

Public Member Functions

 WalManager (const WalManager &)=delete
 
WalManageroperator= (const WalManager &)=delete
 
 WalManager (WalManager &&o) noexcept
 
WalManageroperator= (WalManager &&)=delete
 
 ~WalManager ()
 
expected< int64_t > append (const uint8_t *data, size_t size)
 Append a record to the current segment, rolling to a new segment if needed.
 
expected< int64_t > append (const char *data, size_t size)
 Append a record from a char pointer.
 
expected< int64_t > append (std::string_view sv)
 Append a record from a string_view.
 
std::vector< std::string > segment_paths () const
 List all WAL segment paths in sequence order (oldest first).
 
expected< void > commit_compaction_checkpoint (const std::string &note="")
 Record that an external compaction checkpoint has been made durable, allowing old fully-compacted WAL segments to be pruned safely.
 
void clear_compaction_checkpoint ()
 Reset the checkpoint-ready flag so subsequent prune calls are blocked again until the next commit_compaction_checkpoint().
 
expected< void > remove_segment (const std::string &path)
 Remove a fully-compacted segment from disk and from the tracking list.
 
int64_t total_records () const noexcept
 Total number of records written across all segments (including rolled ones).
 
expected< void > close ()
 Close the manager and the active segment writer.
 
expected< std::vector< WalEntry > > read_all ()
 Read all WAL entries across all segments (sealed and active).
 

Static Public Member Functions

static expected< WalManageropen (const std::string &dir, Options opts={})
 Open a WAL directory, discovering existing segments and creating a new active segment ready for writing.
 

Detailed Description

Manages multiple rolling WAL segment files in a directory.

Automatically rolls to a new segment when the current segment exceeds max_segment_bytes or max_records. Provides crash-recovery read_all() across all segments, compaction checkpoint support, and safe segment pruning.

Thread-safe: all public methods acquire an internal mutex. Non-copyable, move-constructible. Use WalManager::open() to create.

See also
WalWriter, WalReader, WalManagerOptions

Definition at line 806 of file wal.hpp.

Member Typedef Documentation

◆ Options

Alias for the options struct.

Definition at line 809 of file wal.hpp.

Constructor & Destructor Documentation

◆ WalManager() [1/2]

signet::forge::WalManager::WalManager ( const WalManager )
delete

◆ WalManager() [2/2]

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

Definition at line 813 of file wal.hpp.

◆ ~WalManager()

signet::forge::WalManager::~WalManager ( )
inline

Definition at line 825 of file wal.hpp.

Member Function Documentation

◆ append() [1/3]

expected< int64_t > signet::forge::WalManager::append ( const char *  data,
size_t  size 
)
inline

Append a record from a char pointer.

Parameters
dataRecord payload bytes.
sizeNumber of bytes.
Returns
Global sequence number assigned, or Error on failure.

Definition at line 965 of file wal.hpp.

◆ append() [2/3]

expected< int64_t > signet::forge::WalManager::append ( const uint8_t *  data,
size_t  size 
)
inline

Append a record to the current segment, rolling to a new segment if needed.

Parameters
dataPointer to the record payload bytes.
sizeNumber of payload bytes.
Returns
The global sequence number assigned, or Error on failure.

Definition at line 933 of file wal.hpp.

◆ append() [3/3]

expected< int64_t > signet::forge::WalManager::append ( std::string_view  sv)
inline

Append a record from a string_view.

Parameters
svRecord payload.
Returns
Global sequence number assigned, or Error on failure.

Definition at line 972 of file wal.hpp.

◆ clear_compaction_checkpoint()

void signet::forge::WalManager::clear_compaction_checkpoint ( )
inline

Reset the checkpoint-ready flag so subsequent prune calls are blocked again until the next commit_compaction_checkpoint().

Definition at line 1014 of file wal.hpp.

◆ close()

expected< void > signet::forge::WalManager::close ( )
inline

Close the manager and the active segment writer.

Returns
Error on I/O failure.

Definition at line 1056 of file wal.hpp.

◆ commit_compaction_checkpoint()

expected< void > signet::forge::WalManager::commit_compaction_checkpoint ( const std::string &  note = "")
inline

Record that an external compaction checkpoint has been made durable, allowing old fully-compacted WAL segments to be pruned safely.

If checkpoint_manifest_path is configured, writes an atomic marker file. Must be called before remove_segment() when require_checkpoint_before_prune is enabled.

Parameters
noteOptional human-readable note written to the manifest.
Returns
Error on I/O failure.

Definition at line 992 of file wal.hpp.

◆ open()

static expected< WalManager > signet::forge::WalManager::open ( const std::string &  dir,
Options  opts = {} 
)
inlinestatic

Open a WAL directory, discovering existing segments and creating a new active segment ready for writing.

If reset_on_open is true (and lifecycle_mode is not Production), all existing segment files are deleted before starting fresh.

Parameters
dirDirectory path (created if it does not exist).
optsManager options (segment limits, sync policy, lifecycle mode).
Returns
WalManager on success, Error on I/O or policy failure.

Definition at line 836 of file wal.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ read_all()

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

Read all WAL entries across all segments (sealed and active).

The active segment is flushed first so all buffered records become visible to the reader. Records are returned in sequence order.

Returns
All valid WalEntry records across every segment.

Definition at line 1073 of file wal.hpp.

◆ remove_segment()

expected< void > signet::forge::WalManager::remove_segment ( const std::string &  path)
inline

Remove a fully-compacted segment from disk and from the tracking list.

The currently active (most recent) segment cannot be removed. If require_checkpoint_before_prune is enabled, commit_compaction_checkpoint() must be called first.

Parameters
pathFilesystem path of the segment to remove.
Returns
Error if the segment is active, checkpoint not committed, or I/O failure.

Definition at line 1027 of file wal.hpp.

◆ segment_paths()

std::vector< std::string > signet::forge::WalManager::segment_paths ( ) const
inline

List all WAL segment paths in sequence order (oldest first).

Returns
Sorted vector of segment file paths.

Definition at line 978 of file wal.hpp.

◆ total_records()

int64_t signet::forge::WalManager::total_records ( ) const
inlinenoexcept

Total number of records written across all segments (including rolled ones).

Definition at line 1049 of file wal.hpp.


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