Add logging and error handling for file syncing

Add logging and error handling inside, and outside of FileCommit.
Functions such as fsync, fdatasync will return error in case of hardware
I/O errors, and ignoring this means it can silently continue through
data corruption.  (c.f.
https://lwn.net/SubscriberLink/752063/12b232ab5039efbe/)
This commit is contained in:
Wladimir J. van der Laan
2018-04-20 11:21:08 +02:00
parent 8b262eb2d8
commit cf0277928f
4 changed files with 36 additions and 13 deletions

View File

@@ -49,7 +49,8 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
// Serialize
if (!SerializeDB(fileout, data)) return false;
FileCommit(fileout.Get());
if (!FileCommit(fileout.Get()))
return error("%s: Failed to flush file %s", __func__, pathTmp.string());
fileout.fclose();
// replace existing file, if any, with new file