Expand description
§logdb — Embedded Append-Only Log Database
logdb is an embedded, append-only, crash-recoverable, optionally tamper-proof, optionally remotely-pushable local log database.
§Features
- High-throughput append: lock-free fast path with CAS-based ring buffer
- Crash recovery: automatic torn-write detection and truncation on restart
- Optional hash chain: SHA-256 forward-linking for tamper detection (
hash-chainfeature) - Segment management: automatic rolling, configurable retention
- Segment pre-allocation: next segment is pre-created at 80% capacity,
reducing roll-time blocking to a single
fdatasynccall
§Performance: Inline vs Spill
Records ≤ INLINE_CAP (256) bytes take the inline
fast path: zero heap allocation, zero extra memcpy. p50 is typically <100ns.
Records > 256 bytes take the spill path: a heap allocation in the append thread. The spill path is ~4x slower in throughput with ~80x higher p99.9 tail latency due to allocator jitter. Keep latency-sensitive records ≤ 256B.
Structs§
- Config
- Complete configuration for a
LogDbinstance. - KeyRing
- A resolved, in-memory set of AES-256-GCM keys supporting rotation without a disk-format change (cr-032).
- LogDb
- The main log database handle.
- Record
- A fully owned record, typically read back from a segment file.
- Record
Id - Logical position of a record in the log.
- Recovery
Report - Recovery report returned by
LogDb::recovery_report. - Scan
Iter - Public scan iterator returned by
LogDb::scanandLogDb::replay_from. - Tailer
- A named consumer with independent read progress.
- Wait
Strategy - Wait strategy for background thread spinning.
Enums§
- Append
Error - Errors that can occur during
append. - Config
Error - Errors that can occur while validating a
Config. - Durability
Mode - Durability mode for the Committer.
- Flush
Error - Errors that can occur during
flush. - IoBackend
- I/O backend for the Committer.
- Open
Error - Errors that can occur while opening a
LogDb. - Queue
Full Policy - Policy when the ring buffer is full.
- Read
Error - Errors that can occur during
readorscan. - Retention
Policy - Retention policy for old segments.
- Shutdown
Error - Errors that can occur during
shutdown. - Shutdown
Report - Result of a shutdown operation.
- Tailer
Error - Errors that can occur while reading the next batch from a
Tailer.
Functions§
- decode_
record_ id - Decode a global record_id into (shard_id, local_seq).
- encode_
record_ id - Encode a (shard_id, local_seq) pair into a global record_id.
- shard_
bits - Compute the number of bits needed to represent
shards - 1.