Skip to main content

Module storage

Module storage 

Source
Expand description

Persistent Storage with Journaling

Provides crash-resilient persistence for CRDTs using an append-only journal with automatic replay on mount and compaction support.

§Architecture

The journal uses a simple binary format:

┌─────────────┬─────────────┬─────────────────┐
│ Length (4B) │ CRC32 (4B)  │ Payload (N B)   │
└─────────────┴─────────────┴─────────────────┘

Entries are either:

  • Snapshot: Full state replacement (written during compaction)
  • Delta: Incremental update (written on each mutation)

§Recovery

On mount, the journal is replayed entry-by-entry:

  • Snapshots replace the current state
  • Deltas are merged via the CRDT’s Merge trait
  • Truncated entries are ignored (WAL semantics)
  • Checksum failures return an error

§Features

Requires the persistence feature.

§Example

use logicaffeine_system::storage::Persistent;
use logicaffeine_data::crdt::GCounter;

let vfs: Arc<dyn logicaffeine_system::fs::Vfs + Send + Sync> = Arc::new(NativeVfs::new("/data"));
let counter = Persistent::<GCounter>::mount(vfs, "counter.lsf").await?;

counter.mutate(|c| c.increment(5)).await?;
counter.compact().await?; // Reduce journal size

Structs§

Persistent
A persistent CRDT wrapper with journaling (native platform).