logdb
Embedded, append-only, crash-recoverable, optionally tamper-proof local log database. Built in Rust.
Documentation
Full documentation lives under docs/. See the Usage Guide and the Development Guide.
API reference: run cargo doc --open (also available on docs.rs once published).
Quick Start
use ;
let db = open?;
let seq = db.append?;
db.flush?;
let record = db.read?.unwrap;
assert_eq!;
Features
- Lock-free writes: multi-producer CAS ring buffer, p50 < 100ns
- Durability modes: Sync (fsync per batch), Batch (periodic), Async (caller-driven)
- Hash chain (
hash-chainfeature): BLAKE3 keyed tamper-evident integrity - Compression (
compressionfeature): streaming zstd per-frame - Encryption (
encryptionfeature): AES-256-GCM per-frame - WAL checkpoint: persistent, survives crash
- Crash recovery: torn-write detection + hash chain verification
- Sharding: multi-ring for high-core scalability
- Remote push (
remote-pushfeature): async durable record push
As a WAL
// Write
db.append_batch?; // atomic
db.flush?;
db.checkpoint; // persistent
// Recover after crash
let report = db.recovery_report;
// report: { from_sequence, to_sequence, count }
for rec in db.replay_from?
// Ops monitoring
let = db.wal_usage; // WAL space in use
Full example: cargo run --example wal
Feature Flags
| Feature | Default | Description |
|---|---|---|
hash-chain |
off | BLAKE3 keyed hash chain |
compression |
off | Streaming zstd compression |
encryption |
off | AES-256-GCM encryption |
remote-push |
off | Async remote push |
tracing |
off | Structured logging (segment rolls, recovery, retention, flush/drop warnings) |
metrics |
off | Quantitative metrics (counters/histograms/gauges) via the metrics facade |
testing |
off | Re-exposes internals for the deployed test binary (not a supported API) |
Shutdown & drop
LogDb spawns background threads (Committer, Sealer). For guaranteed
durability, call shutdown(timeout) (consumes the handle, joins threads) or
drain(timeout) (shared-safe, flushes without consuming). Drop performs a
best-effort bounded drain (≤5 s) of already-published records and emits a
tracing warning if it cannot finish — a safety net, not a guarantee. It is
skipped during panic unwinding.
Testing
Architecture
Many producer threads
│ append(content)
▼
┌─────────────────────────┐
│ Ring (optionally sharded) │ ← lock-free CAS claim, inline ≤ 256B = zero alloc
│ Slot: { content, hash } │
└──────────┬──────────────┘
│
(optional) Sealer thread ← BLAKE3 keyed hash chain
│
Committer thread ← batch serialize + pwrite + fdatasync
│
┌──────┴──────┐
│ Segment file │ ← append-only, rolls when full, checkpoint-truncated
└─────────────┘
│
Reader / Pusher ← point/range reads / remote push
Performance baseline (SATA SSD, 8-vCPU cloud VM)
| Metric | Value |
|---|---|
| append(64B) p50 | 54ns |
| append(256B) p50 | 57ns |
| append(256B) p99 | 230ns |
| append(256B) 1-thread throughput | 3.79M rec/s |
| append(256B) 4-thread throughput | 4.48M rec/s |
| End-to-end durability p99 | 10.4ms (<2ms expected on NVMe) |
| Segment-roll pause | 0ms (pre-allocation + idle drain) |
| Range scan (cr-004, 64B records) | ~90 ns/rec (~12× over the per-record-syscall path) |
License
Apache-2.0. Third-party attributions: THIRDPARTY.md.
Security
Using the encryption or hash-chain features? Read the
threat model and
key management first. To report a
vulnerability, see ../SECURITY.md.