Skip to content

feat: Add Write-Ahead Log for Crash Durability - #19

Merged
ThomasHartDev merged 2 commits into
mainfrom
thomas/feat/wal-durability
Sep 4, 2026
Merged

feat: Add Write-Ahead Log for Crash Durability#19
ThomasHartDev merged 2 commits into
mainfrom
thomas/feat/wal-durability

Conversation

@ThomasHartDev

Copy link
Copy Markdown
Owner

Kafka, Postgres, and SQLite all append to a log before they treat a write as durable. This adds that piece: a length-prefixed WAL with IEEE CRC32 over each length prefix and payload, fsync before append returns, and recovery that replays complete records then truncates at the first bad CRC or incomplete header. Eight zero bytes at the tail are not a valid record, and nothing after that hole is replayed.

DurableWorkQueue writes enqueue, ack, and drop records before it touches the in-memory WorkQueue. A restart redelivers unacked work and does not resurrect acked work. Unsubscribing requeues in-flight work without writing ack or drop, so a stale ack or nack on the old Delivery cannot erase it from the log. checkpoint() rewrites the file to the live enqueue records via a temp file, fsync, and rename. The package barrel also exports the dead-letter types again, which the work-queue merge dropped.

Closes #18

Append-only log with length-prefixed records, a CRC32 on each payload,
and fsync before append returns. Open replays complete records and
truncates a torn or checksum-mismatched tail. DurableWorkQueue logs
enqueue, ack, and drop before the in-memory mutation so a restart
redelivers unacked work and does not resurrect acked work.
Checksum the length prefix with the payload so eight zero bytes are not
a valid empty record. Honor short read and write counts. Mark in-flight
durable deliveries settled on unsubscribe without writing ack or drop.
@ThomasHartDev
ThomasHartDev force-pushed the thomas/feat/wal-durability branch from a2d74bf to 3a72703 Compare September 4, 2026 19:32
@ThomasHartDev
ThomasHartDev merged commit f6e7d02 into main Sep 4, 2026
@ThomasHartDev
ThomasHartDev deleted the thomas/feat/wal-durability branch September 4, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write-ahead log for crash durability

1 participant