Append-only Write-Ahead Log writer with CRC-32 integrity per record.
More...
#include <wal.hpp>
|
| | WalWriter (const WalWriter &)=delete |
| |
| WalWriter & | operator= (const WalWriter &)=delete |
| |
| | WalWriter (WalWriter &&o) noexcept |
| |
| WalWriter & | operator= (WalWriter &&)=delete |
| |
| | ~WalWriter () |
| |
| expected< int64_t > | append (const uint8_t *data, size_t size) |
| | Append a raw-byte record to the WAL.
|
| |
| expected< int64_t > | append (const std::vector< uint8_t > &data) |
| | Append a record from a byte vector.
|
| |
| 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.
|
| |
| expected< void > | flush (bool do_fsync=false) |
| | Flush the stdio buffer to the OS page cache.
|
| |
| expected< void > | close () |
| | Seal the WAL file: flush buffered data, fsync, and close the file handle.
|
| |
| bool | is_open () const noexcept |
| | True if the writer is open and accepting appends.
|
| |
| int64_t | next_seq () const noexcept |
| | The sequence number that will be assigned to the next appended record.
|
| |
| const std::string & | path () const noexcept |
| | Filesystem path of the WAL file.
|
| |
| int64_t | bytes_written () const noexcept |
| | Total bytes written to this WAL file (header + all records).
|
| |
| uint64_t | rejected_empty_count () const noexcept |
| | Number of empty records rejected (CWE-754).
|
| |
Append-only Write-Ahead Log writer with CRC-32 integrity per record.
Each record is written as: [magic(4)][seq(8)][ts_ns(8)][size(4)][data(N)][crc32(4)]. Thread-safe: all public methods acquire an internal mutex.
Non-copyable, move-constructible. Use WalWriter::open() to create.
- See also
- WalReader, WalManager, WalWriterOptions
Definition at line 236 of file wal.hpp.
◆ Options
Alias for the options struct.
Definition at line 239 of file wal.hpp.
◆ WalWriter() [1/2]
| signet::forge::WalWriter::WalWriter |
( |
const WalWriter & |
| ) |
|
|
delete |
◆ WalWriter() [2/2]
| signet::forge::WalWriter::WalWriter |
( |
WalWriter && |
o | ) |
|
|
inlinenoexcept |
◆ ~WalWriter()
| signet::forge::WalWriter::~WalWriter |
( |
| ) |
|
|
inline |
◆ append() [1/4]
| expected< int64_t > signet::forge::WalWriter::append |
( |
const char * |
data, |
|
|
size_t |
size |
|
) |
| |
|
inline |
Append a record from a char pointer.
- Parameters
-
| data | Record payload bytes (reinterpreted as uint8_t). |
| size | Number of bytes. |
- Returns
- Sequence number assigned, or Error on failure.
Definition at line 477 of file wal.hpp.
◆ append() [2/4]
| expected< int64_t > signet::forge::WalWriter::append |
( |
const std::vector< uint8_t > & |
data | ) |
|
|
inline |
Append a record from a byte vector.
- Parameters
-
| data | Record payload bytes. |
- Returns
- Sequence number assigned, or Error on failure.
Definition at line 469 of file wal.hpp.
◆ append() [3/4]
| expected< int64_t > signet::forge::WalWriter::append |
( |
const uint8_t * |
data, |
|
|
size_t |
size |
|
) |
| |
|
inline |
Append a raw-byte record to the WAL.
Writes a complete record (header + payload + CRC-32) atomically under the internal mutex. If sync_on_append is enabled, fsyncs after each write.
- Parameters
-
| data | Pointer to the record payload bytes. |
| size | Number of payload bytes (must be > 0 and <= UINT32_MAX). |
- Returns
- The sequence number assigned to this record, or Error on failure.
Definition at line 397 of file wal.hpp.
◆ append() [4/4]
| expected< int64_t > signet::forge::WalWriter::append |
( |
std::string_view |
sv | ) |
|
|
inline |
Append a record from a string_view.
- Parameters
-
- Returns
- Sequence number assigned, or Error on failure.
Definition at line 484 of file wal.hpp.
◆ bytes_written()
| int64_t signet::forge::WalWriter::bytes_written |
( |
| ) |
const |
|
inlinenoexcept |
Total bytes written to this WAL file (header + all records).
Definition at line 534 of file wal.hpp.
◆ close()
| expected< void > signet::forge::WalWriter::close |
( |
| ) |
|
|
inline |
Seal the WAL file: flush buffered data, fsync, and close the file handle.
- Returns
- Error on I/O failure.
Definition at line 510 of file wal.hpp.
◆ flush()
| expected< void > signet::forge::WalWriter::flush |
( |
bool |
do_fsync = false | ) |
|
|
inline |
Flush the stdio buffer to the OS page cache.
If do_fsync is true (or sync_on_flush is enabled in Options), also performs a durable fsync to storage media.
- Parameters
-
| do_fsync | Force an fsync regardless of Options. |
- Returns
- Error on I/O failure.
Definition at line 495 of file wal.hpp.
◆ is_open()
| bool signet::forge::WalWriter::is_open |
( |
| ) |
const |
|
inlinenoexcept |
True if the writer is open and accepting appends.
Definition at line 528 of file wal.hpp.
◆ next_seq()
| int64_t signet::forge::WalWriter::next_seq |
( |
| ) |
const |
|
inlinenoexcept |
The sequence number that will be assigned to the next appended record.
Definition at line 530 of file wal.hpp.
◆ open()
Open or create a WAL file for appending.
If the file already exists, it is scanned to determine the next sequence number so appends continue without gaps. The file header is written only when the file is first created (empty).
- Parameters
-
| path | Filesystem path to the WAL file. |
| opts | Writer options (sync policy, buffer size, start sequence). |
- Returns
- WalWriter on success, Error on I/O failure.
Definition at line 270 of file wal.hpp.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ path()
| const std::string & signet::forge::WalWriter::path |
( |
| ) |
const |
|
inlinenoexcept |
Filesystem path of the WAL file.
Definition at line 532 of file wal.hpp.
◆ rejected_empty_count()
| uint64_t signet::forge::WalWriter::rejected_empty_count |
( |
| ) |
const |
|
inlinenoexcept |
Number of empty records rejected (CWE-754).
Definition at line 536 of file wal.hpp.
The documentation for this class was generated from the following file: