![]() |
Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
|
DEMO |
High-performance WAL writer using a ring of N memory-mapped segments. More...
#include <wal_mapped_segment.hpp>
Public Member Functions | |
| WalMmapWriter (const WalMmapWriter &)=delete | |
| WalMmapWriter & | operator= (const WalMmapWriter &)=delete |
| WalMmapWriter (WalMmapWriter &&o) | |
| WalMmapWriter & | operator= (WalMmapWriter &&o) |
| ~WalMmapWriter () | |
| expected< int64_t > | append (const uint8_t *data, size_t size) |
| Append a record to the WAL. | |
| expected< int64_t > | append (const char *data, size_t size) |
| Append a record from a char buffer. | |
| expected< int64_t > | append (std::string_view sv) |
| Append a record from a string_view. | |
| expected< int64_t > | append (const std::vector< uint8_t > &v) |
| Append a record from a byte vector. | |
| expected< void > | flush (bool do_sync=false) |
| Flush the active segment to storage. | |
| expected< void > | close () |
| Close the writer: stop the background thread, flush and close all segments. | |
| bool | is_open () const noexcept |
| Check whether the writer is still open (not yet closed). | |
| int64_t | next_seq () const noexcept |
| Return the next sequence number that will be assigned. | |
| const std::string & | dir () const noexcept |
| Return the output directory path. | |
| std::vector< std::string > | segment_paths () const |
| Return paths of all current ring segments plus any older WAL files in the directory. | |
Static Public Member Functions | |
| static expected< WalMmapWriter > | open (WalMmapOptions opts) |
| Open a new WalMmapWriter in the given directory. | |
High-performance WAL writer using a ring of N memory-mapped segments.
Achieves sub-microsecond append latency (~223 ns) by writing directly into mmap'd memory. A background thread pre-allocates and pre-faults standby segments so rotation is nearly free.
File format: Identical to WalWriter (WAL_FILE_MAGIC at byte 0, records at byte 16). WalReader works unchanged on WalMmapWriter segment files.
Thread safety: NOT thread-safe for concurrent appends. Single-writer model. flush() and close() must be called from the same thread as append().
Crash safety: CRC is written LAST with a release fence. WalReader stops at bad/missing CRC, recovering all complete records.
Definition at line 450 of file wal_mapped_segment.hpp.
|
delete |
|
inline |
Definition at line 455 of file wal_mapped_segment.hpp.
|
inline |
Definition at line 508 of file wal_mapped_segment.hpp.
|
inline |
Append a record from a char buffer.
| data | Pointer to the record payload. |
| size | Size of the payload in bytes. |
Definition at line 685 of file wal_mapped_segment.hpp.
|
inline |
Append a record from a byte vector.
| v | The record payload. |
Definition at line 699 of file wal_mapped_segment.hpp.
|
inline |
Append a record to the WAL.
Returns the assigned sequence number.
NOT thread-safe – single-writer model. Automatically rotates to the next segment when the active segment is full. Wakes the background thread when the active segment is 75% full.
| data | Pointer to the record payload. |
| size | Size of the payload in bytes (max 4 GB). |
Definition at line 601 of file wal_mapped_segment.hpp.
|
inline |
Append a record from a string_view.
| sv | The record payload. |
Definition at line 692 of file wal_mapped_segment.hpp.
|
inline |
Close the writer: stop the background thread, flush and close all segments.
Definition at line 717 of file wal_mapped_segment.hpp.
|
inlinenoexcept |
Return the output directory path.
Definition at line 749 of file wal_mapped_segment.hpp.
|
inline |
Flush the active segment to storage.
| do_sync | If true (or opts_.sync_on_flush), use synchronous flush; otherwise async. |
Definition at line 706 of file wal_mapped_segment.hpp.
|
inlinenoexcept |
Check whether the writer is still open (not yet closed).
Definition at line 745 of file wal_mapped_segment.hpp.
|
inlinenoexcept |
Return the next sequence number that will be assigned.
Definition at line 747 of file wal_mapped_segment.hpp.
|
inlinestatic |
Open a new WalMmapWriter in the given directory.
Creates the directory if it does not exist. Synchronously allocates and pre-faults the first segment; the background thread is started after the returned writer is moved into its final location.
| opts | Writer options (directory, segment size, ring count, etc.). |
Definition at line 521 of file wal_mapped_segment.hpp.
|
delete |
|
inline |
Definition at line 480 of file wal_mapped_segment.hpp.
|
inline |
Return paths of all current ring segments plus any older WAL files in the directory.
Definition at line 755 of file wal_mapped_segment.hpp.