Expand description
Write-Ahead Logging (WAL) for crash recovery.
This module implements a write-ahead log that ensures durability and enables crash recovery for storage operations. All mutations are logged before being applied, allowing recovery from incomplete operations after a crash.
§Example
use chie_core::wal::{WriteAheadLog, LogEntry, Operation};
use std::path::PathBuf;
let mut wal = WriteAheadLog::new(PathBuf::from("/tmp/wal")).await?;
// Log a write operation
let entry = LogEntry {
sequence: 1,
operation: Operation::WriteChunk {
cid: "QmTest".to_string(),
chunk_index: 0,
data: vec![1, 2, 3],
},
timestamp_ms: 1234567890,
};
wal.append(&entry).await?;
// Replay log after crash
let entries = wal.replay().await?;
for entry in entries {
// Apply logged operations
}
// Truncate log after successful checkpoint
wal.truncate(10).await?;Structs§
- LogEntry
- A log entry in the WAL.
- Write
Ahead Log - Write-ahead log for crash recovery.