aiondb-wal

Write-ahead log. Encodes every durable mutation (DML, DDL, catalog change, transaction control, checkpoint, replication marker) into typed WalRecord entries, stores them in segmented files in the WAL directory, fsyncs on commit, and replays them at startup. Supports group-commit batching, optional LZ4 / Zstd payload compression, and two LSN progression modes (sequential or byte-offset).

Format integrity and authenticity are distinct:

The local HMAC path is designed to minimize steady-state overhead:

cargo

[dependencies]
aiondb-wal = { path = "../aiondb-wal" }

modules

modulepurpose
recordWalRecord enum (every record kind) and the wire WalEntry envelope.
writerWalWriter appender, segment rotation, group commit, durable flush.
readerWalReader segment iterator used during recovery.
segmentsegment file layout, naming, archival, restore helpers, local integrity sidecars.
codecrecord encoding/decoding, optional compression, prepared records.
lsnthe Lsn type.
replicationReplicaRegistry and WalNotifier for follower fan-out.

key types

typerole
WalConfigdirectory, max segment bytes, fsync flag, group-commit delay, compression mode, LSN mode.
WalCompressionNone, Lz4, Zstd for payload compression.
WalLsnModeLogical (sequential counter) or ByteOffset (byte-position progression).
WalWriterappends WalRecords to the active segment; handles rotation, flush, and durable sync.
WalReaderiterates entries from a starting LSN across segments.
WalRecordenum of every record kind: DML, DDL, catalog mutations, transaction begin/commit/abort, checkpoint, full-page image, page patch, replication marker.
WalEntryon-disk envelope { lsn, prev_lsn, database_id, record }.
Lsn64-bit log sequence number; ZERO, advance, checked_advance, from_str_value.
AppendBatchResult{ last_lsn, total_bytes } from a batched append.
IsolationLevelre-exported from aiondb-tx for use in BeginTxn.

The segment module additionally exposes free functions for segment management: ensure_wal_dir, list_segments, list_segments_if_exists, open_segment_for_append, open_segment_for_read, recycle_segment, remove_segment, archive_segment_to_dir, restore_segment_from_dir, archive_dir_from_env, inspect_segment_header, sync_dir, verify_local_wal_dir_if_configured.

writer api

methoduse
WalWriter::open(WalConfig)open or create the WAL directory; recovers the next LSN by scanning segments and verifies local HMAC sidecars when configured.
append(&WalRecord) -> DbResult<Lsn>append a record to the active segment.
append_prepared(&PreparedWalRecord)append a record whose payload was pre-encoded.
flush() -> DbResult<()>flush the buffered writer to the OS.
flush_durable() -> DbResult<()>flush and fsync the current segment; if local WAL HMAC is configured, persists the matching .auth sidecar for the trusted byte length.
next_lsn(), last_lsn(), last_entry_bytes(), current_segment()introspection.
remove_segments_before(Lsn)trim segments older than Lsn.

example

use aiondb_core::TxnId;
use aiondb_wal::{IsolationLevel, Lsn, WalConfig, WalRecord, WalWriter};

let cfg = WalConfig {
    dir: "/var/lib/aiondb/wal".into(),
    ..Default::default()
};

let mut writer = WalWriter::open(cfg).expect("open wal");
let txn = TxnId::new(1);

let _begin: Lsn = writer
    .append(&WalRecord::BeginTxn {
        txn_id: txn,
        isolation: IsolationLevel::ReadCommitted,
    })
    .expect("log begin");

let _commit: Lsn = writer
    .append(&WalRecord::CommitTxn {
        txn_id: txn,
        commit_ts: 0,
    })
    .expect("log commit");

writer.flush_durable().expect("fsync");

local integrity

Configure one of these environment variables on every process that writes or replays WAL:

AIONDB_WAL_LOCAL_HMAC_KEY takes precedence. The key must stay outside the writable data directory; storing it next to the WAL defeats the threat model.

With a configured key:

Without a configured key: