The storage module provides persistence, versioned data handling, blob and tiered storage behavior, WAL/durability paths, crash-recovery guarantees, backup-recovery behavior, and storage-level observability for ThemisDB. It forms the foundation for all durable operations and must provide strict ACID guarantees, deterministic recovery, and fail-closed safety.
| Interface / File | Role |
|---|---|
| include/storage/storage_module.h | Doxygen module entry point for storage-wide API grouping |
| include/storage/storage_api_contract.h | API contract: error codes, guarantees, determinism model |
| rocksdb_wrapper.cpp | RocksDB integration and durable storage wrapper behavior |
| storage_engine.cpp | storage orchestration and lifecycle behavior |
| mvcc_store.cpp | MVCC version/snapshot behavior |
| wal_storage.cpp | WAL durability path, sync guarantees, replay behavior |
| backup_manager.cpp | backup creation, lifecycle, and restorability behavior |
| pitr_manager.cpp | point-in-time recovery with exact-timestamp determinism |
| tiered_storage.cpp | tiered data placement (hot/warm/cold) with automated migration |
| blob_redundancy_manager.cpp | blob redundancy and integrity behavior |
| encrypted_blob_backend.cpp | encrypted blob backend behavior |
| erasure_coding_backend.cpp | erasure-coded backend behavior |
| compaction_manager.cpp | compaction control and cleanup behavior |
| adaptive_compaction.cpp | adaptive compaction behavior under load |
| index_maintenance.cpp | storage-side index maintenance behavior |
| storage_audit_logger.cpp | storage audit trail generation |
| security_signature_manager.cpp | storage signature/integrity/tamper-detection behavior |
In scope:
- Durable key-value and blob/tiered storage persistence
- MVCC/WAL/backup/PITR/compaction and lifecycle behavior
- Storage integrity, audit, and maintenance surfaces
- Fail-closed recovery paths and crash-recovery determinism
- ACID guarantee enforcement and verification
- Tiered storage automation and configuration transparency
Out of scope:
- Query planning and non-storage API orchestration
- External business-domain logic outside storage boundaries
- Network transport (handled by replication module)
- Encryption key lifecycle (handled by security module)
- Durable write guarantee: All writes passed to
Storage::write()are guaranteed durable on return whensync_mode=SYNCorBATCH_SYNC. - MVCC invariant: Snapshots remain valid for their lifetime; reads are never dirty or inconsistent.
- WAL durability: Every durable write is preceded by WAL entry durability; replay is deterministic and idempotent.
- Crash recovery: Unclean shutdown recovery is deterministic; no data loss (MVCC-enabled) and no state corruption.
- Backup guarantee: Backups are atomic point-in-time copies with full consistency across all layers.
- PITR accuracy: Recovery to a specific timestamp ±100ms; no log gaps, no partial transactions.
- Tiered migration: Age-based and access-frequency-based tier migration is transparent to readers; no observable latency spike on promotion.
- Configuration scope: Behavior is bounded by storage configuration; all limits are enforced with explicit error on overage.
🟡 Wave A Candidate (Runtime Reliability Focus)
- ✅ ACID core (persistence, MVCC, WAL, recovery) is proven under stress testing
- ✅ Fail-closed behavior is implemented and chaos-tested for crash recovery
- ✅ Deterministic replay verified under sustained write load
- ✅ Backup/PITR/tiered storage integration is complete
⚠️ Outstanding Wave A Item: Stress validation under maintenance-overlap scenarios (Q3–Q4 2026)⚠️ Outstanding Wave A Item: Benchmark-backed release guardrails for hot paths (Q3–Q4 2026)
- API contract frozen (storage_api_contract.h with explicit error taxonomy)
- Error taxonomy complete (12 error codes, deterministic mapping)
- Fail-closed paths verified (recovery, replay, backup restorability)
- Thread-safety model documented (MVCC isolation, lock ordering)
- Concurrency gates implemented and benchmarked
- [~] Sustained-load chaos evidence collection (Target: Q3 2026)
- [~] Representative-hardware p95/p99 baseline refresh (Target: Q4 2026)
- MVCC Isolation: Snapshots created via
getSnapshot()are isolated; concurrent writes do not affect ongoing reads. - Lock Ordering: Internal lock hierarchy is strictly enforced:
mvcc_lock→wal_lock→compaction_lock. No circular waits. - Write Serialization: Writes are serialized through
write_coordinatorwith deterministic ordering. - WAL Thread-Safety: WAL writer is single-threaded; concurrent write calls are queued and processed serially.
- Compaction Safety: Compaction runs with a reader-writer lock; snapshot references prevent compaction of live versions.
Reads (many) Writes (1 at a time) Maintenance
│ │ │
├─ snapshot ────────────├─ write ────────────────┤
│ (MVCC) │ (sync to WAL) │ (compaction,
│ no lock │ update MVCC │ backup,
│ on read │ → release WAL │ PITR)
│ │ │
└─────────────────────────────────────────────────┘
Isolation via MVCC versioning
- MVCC map access: Protected by fine-grained RW lock; read-heavy optimization
- WAL buffer filling: Ring buffer with lock-free enqueue for low-contention writes
- Compaction frequency: Adaptive compaction throttles based on load; avoids write stall
- Tiered storage promotion: Background task; never blocks foreground I/O
- WAL Replay: On startup, all WAL entries are replayed in order; order is idempotent (no double-apply risk).
- MVCC Consistency: Partial transactions are rolled back; orphaned snapshots are cleaned up.
- Blob Integrity: Checksums verified on recovery; corrupted blobs trigger recovery failure (explicit error).
- Backup Verification: Backups are validated on restore; corrupt backup rejected with explicit error.
- State Durability: In-flight compaction is atomic or rolled back; no partial compactions.
- On WAL write failure: Transaction fails immediately; caller never observes partial state.
- On storage exhaustion: Write is rejected with
STORAGE_EXHAUSTEDerror; state unmodified. - On recovery failure: Startup fails fast with diagnostic context; no silent corruption.
- On backup failure: Backup is rolled back; incomplete backup is not used.
- On PITR timestamp mismatch: Recovery fails with explicit error; no approximate recovery.
- ✅ Unclean shutdown: WAL replay is deterministic (tested via chaos injection)
- ✅ Partial writes: MVCC rolls back orphaned snapshots (tested)
- ✅ Compaction crash: Atomic or rolled back, no state corruption (tested)
- ✅ Backup corruption: Validated on restore, rejected with error (tested)
- ✅ Storage pressure: Tiered migration and cleanup enforce limits (tested)
-
Verified core files (15+):
src/storage/rocksdb_wrapper.cpp— RocksDB wrapper and durability enforcementsrc/storage/storage_engine.cpp— orchestration and lifecyclesrc/storage/mvcc_store.cpp— MVCC versioning and snapshot lifecyclesrc/storage/wal_storage.cpp— WAL durability and replay guaranteesrc/storage/backup_manager.cpp— backup atomicity and restorabilitysrc/storage/pitr_manager.cpp— point-in-time recovery with exact determinismsrc/storage/tiered_storage.cpp— tiered migration automationsrc/storage/blob_redundancy_manager.cpp— blob redundancy enforcementsrc/storage/encrypted_blob_backend.cpp— encrypted blob storagesrc/storage/erasure_coding_backend.cpp— erasure-coded storagesrc/storage/compaction_manager.cpp— compaction lifecyclesrc/storage/adaptive_compaction.cpp— adaptive compactionsrc/storage/index_maintenance.cpp— index maintenancesrc/storage/storage_audit_logger.cpp— audit trail generationsrc/storage/security_signature_manager.cpp— integrity verification
-
Verified behavior surfaces:
- ACID persistence, MVCC isolation, WAL durability, crash recovery, backup/PITR, tiering, audit
-
Documentation structure:
- API contract in
include/storage/storage_api_contract.h(error codes, guarantees, determinism) - Production requirements in
src/storage/PRODUCTION_REQUIREMENTS.md(checklist, gates) - Forward planning tracked in
ROADMAP.md(phases, Wave A/B/C/D alignment) - Historical entries in
CHANGELOG.md
- API contract in
Next Step: See ROADMAP.md for Batch 4 Wave A (Runtime Reliability) closure plan and Q3–Q4 2026 timeline.