Expand description
Incremental checkpointing - Directory-based checkpoint architecture
§Incremental Checkpointing
Three-tier incremental checkpoint architecture that maintains Ring 0 latency (<500ns) while providing durable, incremental state snapshots.
§Architecture
Ring 0 (Hot, <500ns):
Event ──▶ mmap_state.put() ──▶ changelog.push(offset_ref)
(zero-alloc)
│
▼ async drain when idle
Ring 1 (Background):
changelog.drain() ──▶ wal.append() ──▶ wal.sync()
(group commit, fdatasync)
│
▼ periodic checkpoint
wal.replay(last_ckpt..now) ──▶ state.apply_batch()
state.create_checkpoint() ──▶ snapshot to directory
wal.truncate(checkpoint_epoch)§Core Invariant
Checkpoint(epoch) + WAL.replay(epoch..current) = Consistent State§Key Components
StateChangelogEntry: Zero-alloc changelog entry (32 bytes)StateChangelogBuffer: Ring 0 SPSC changelog bufferIncrementalCheckpointManager: Directory-based incremental checkpointsRecoveryManager: Checkpoint + WAL recovery
§Example
use laminar_storage::incremental::{
IncrementalCheckpointManager, CheckpointConfig, RecoveryConfig, RecoveryManager,
};
use std::path::Path;
use std::time::Duration;
// Create checkpoint manager
let config = CheckpointConfig::new(Path::new("/data/checkpoints"))
.with_wal_path(Path::new("/data/wal"))
.with_interval(Duration::from_secs(60))
.with_max_retained(3);
let mut manager = IncrementalCheckpointManager::new(config).unwrap();
// Create incremental checkpoint
let metadata = manager.create_checkpoint(100).unwrap();
println!("Created checkpoint {} at epoch {}", metadata.id, metadata.epoch);
// Recovery
let recovery_config = RecoveryConfig::new(Path::new("/data/checkpoints"), Path::new("/data/wal"));
let recovery_manager = RecoveryManager::new(recovery_config);
let recovered = recovery_manager.recover().unwrap();
println!("Recovered to epoch {} with {} source offsets",
recovered.epoch, recovered.source_offsets.len());Structs§
- Checkpoint
Config - Configuration for incremental checkpointing.
- Incremental
Checkpoint Manager - Incremental checkpoint manager.
- Incremental
Checkpoint Metadata - Metadata for an incremental checkpoint.
- Recovered
State - Recovered state from checkpoint + WAL replay.
- Recovery
Config - Configuration for recovery.
- Recovery
Manager - Recovery manager for restoring state from checkpoints and WAL.
- State
Changelog Buffer - Ring 0 SPSC changelog buffer for state mutations.
- State
Changelog Entry - Zero-allocation changelog entry for Ring 0 hot path.
Enums§
- Incremental
Checkpoint Error - Errors that can occur during incremental checkpointing.
- StateOp
- State mutation operation type.
Functions§
- validate_
checkpoint - Validates a checkpoint directory.
- wal_
size - Calculates the WAL size for checkpoint decisions.