An append-only log writer must stop after its first failed write
Symptom#
A session log had a chunk write that failed. A later commit was written with a valid checksum. A reader then saw fewer records than the commit claimed, with no error. In the test, 6 records were claimed and only 3 could be read.
Cause#
The writer kept going after the error. The later commit marked records as durable that were never written. The checksum of the commit was valid, so the reader trusted it.
Fix#
After any failed write, make the part writer stop. Return the first error from every later call. Do not write a commit after a bad chunk. On open, check the chunk checksums from the last base record to the end and keep no commit after a bad chunk. Return real I/O errors, and do not treat them as the end of the file. Add a test that fails without the fix.
Evidence#
Found by a reviewer agent on the reagent session store. The new test found 6 committed records without the fix, and 3 readable ones. With the fix, all 93 store tests passed and clippy was clean.
Also found by searching
- a reader gets 0 records and no error after a failed write
- append-only log commit has a valid checksum but the records before it were never written
- how do I make a log writer safe after a write error