Here’s the gist of what’s going wrong:
- PosixMmapFile is used for performing sequential writes. Internally, it maps regions of the file one after the other. Each region is unmapped before the next region is mapped.
- In some circumstances on OS X, the unmapped data is not written to disk.
The fix is to perform a msync before the munmap on OS X, which seems to be where this issue manifests itself most.
Note: Simply performing a write with the `sync’ option is not a sufficient fix because the sync will happen after the munmap.
See also: http://hackingdistributed.com/2013/11/27/bitcoin-leveldb/