WAL Recovery¶
Grafeo uses Write-Ahead Logging (WAL) to ensure durability and enable crash recovery.
How WAL Works¶
- Log First - All changes are written to the WAL before being applied
- Apply Changes - Changes are applied to the main data files
- Checkpoint - Periodically, WAL is merged into data files
- Truncate - Old WAL entries are removed after checkpointing
Crash Recovery¶
When opening a database after a crash:
- Grafeo detects incomplete transactions in the WAL
- Committed transactions are replayed
- Uncommitted transactions are rolled back
- Database is restored to a consistent state
# Recovery happens automatically on open
db = grafeo.Database(path="my_graph.db")
# Database is now in a consistent state
Checkpointing¶
Checkpoints merge WAL changes into the main data files:
Durability Levels¶
| Level | Description |
|---|---|
| Transaction Durability | Each committed transaction is durable |
| Session Durability | All session changes persist after close |
| Database Durability | Data survives process crash |
Best Practices¶
- Regular Checkpoints - Reduce recovery time
- Sufficient Disk Space - WAL can grow between checkpoints
- Proper Shutdown - Use
close()when possible