Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Corruption of persistent database file cause by sudden lost of power #189
It looks like when the persistent file is being save there is a tiny amount of time where a sudden power lost will cause the persistent database file to be corrupted.
Thousands of sudden power lost on our system were performed we notice the following:
We have a similar problem with another application that we build and reading into Linux documentation, we found out that flushing or closing a file is not enough to write the content to disk. An fsync need to be perform to confirm that the content is written to disk.
You can see the documentation in the man page (man close, under "note" second paragraph) on Fedora 23.
"A successful close does not guarantee that the data has been successfully saved to disk, as the kernel defers writes. It is not common for a filesystem to flush the buffers when the stream is closed. If you need to be sure that the data is physically stored, use fsync(2). (It will depend on the disk hardware at this point.)"
added a commit
Jun 26, 2016
Recommend calling fflush before fsync to ensure that application buffers are completely flushed to kernel buffer before being flushed to disk. It's awful hard to reproduce this, but between thanhvtruong and myself we started a long-term test series to mechanically verify.
I do not believe the directory sync is required; the rename logic should work as-is.
I opened a pull requrest for these changes and will update as the long-term tests progress.