-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
Summary
Database commits are not atomic - a crash during commit can leave the database in an inconsistent state with orphaned blocks. Implement a write-ahead log (WAL) for atomic commits with crash recovery.
Problem
In core/blockstore/commitor.ts, blocks are written individually. If a crash occurs mid-commit:
- Some blocks may be written, others not
- The meta record may point to non-existent blocks
- Orphaned blocks consume storage without being reachable
Proposed Solution
- Design WAL entry format for commit operations
- Create
WALServiceatcore/blockstore/wal-service.ts - Implement IndexedDB WAL storage
- Implement two-phase commit protocol:
- Begin: Write WAL entry with commit intent
- Record: Write blocks with WAL reference
- Commit: Update meta record
- Finalize: Remove WAL entry
- Implement rollback with orphan cleanup
- Implement crash recovery on database open
- Integrate WAL into commitor
Expected Outcomes
- All blocks in commit succeed or fail together
- Partial failures trigger complete rollback
- Crash recovery restores consistent state
- Optional feature flag for WAL
Dependencies
Should be implemented after the validateBlocks async fix (PR #1494).
Metadata
Metadata
Assignees
Labels
No labels