This is useful for pruning stale data without bloating the database file.
It should be more stable now.
This will deadlock the entire loop.
Also refactor the write engine a little so that we know the write offset when writing it. This allows the index to be updated on write completion and we now use a single fd for reading and writing.