Bug hunting: Deadlocks, data safety, and dumb shit
- Don't preallocate index files, instead just ftruncate() them to size.
Index locality is pretty well moot when we're never reading more than
50 entries at a time.
- Factor out data remapping
- Added extra bounds checks for segments and records
- Wasn't actually updating blerg->current_segment when switching
segments, causing deadlock when the second record is written in a new
segment.
- Use posix_fallocate() instead of writing zeroes
- Update record count *after* successfully writing a record, not before
- Use fstat to determine new record data offset instead of ftell (not
sure if this is better, but it sure looks cleaner).
- Don't bother trying to write the rest of the data when we get a short
write. Truncate and move on.