mdbx: refine mdbx_filesync() to avoid hide fdatasync() error.

This commit is contained in:
Leo Yuriev 2019-03-04 13:53:05 +03:00
parent 9f410597df
commit 9ffd17d58b

View File

@ -674,29 +674,26 @@ int mdbx_filesync(mdbx_filehandle_t fd, bool filesize_changed) {
(void)filesize_changed; (void)filesize_changed;
return FlushFileBuffers(fd) ? MDBX_SUCCESS : GetLastError(); return FlushFileBuffers(fd) ? MDBX_SUCCESS : GetLastError();
#else #else
for (;;) { int rc;
/* LY: It is no reason to use fdatasync() here, even in case do {
* no such bug in a kernel. Because "no-bug" mean that a kernel
* internally do nearly the same, e.g. fdatasync() == fsync()
* when no-kernel-bug and file size was changed.
*
* So, this code is always safe and without appreciable
* performance degradation.
*
* For more info about of a corresponding fdatasync() bug
* see http://www.spinics.net/lists/linux-ext4/msg33714.html */
#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
if (!filesize_changed && fdatasync(fd) == 0) /* LY: This code is always safe and without appreciable performance
return MDBX_SUCCESS; * degradation, even on a kernel with fdatasync's bug.
*
* For more info about of a corresponding fdatasync() bug
* see http://www.spinics.net/lists/linux-ext4/msg33714.html */
if (!filesize_changed) {
if (fdatasync(fd) == 0)
return MDBX_SUCCESS;
} else
#else #else
(void)filesize_changed; (void)filesize_changed;
#endif #endif
if (fsync(fd) == 0) if (fsync(fd) == 0)
return MDBX_SUCCESS; return MDBX_SUCCESS;
int rc = errno; rc = errno;
if (rc != EINTR) } while (rc == EINTR);
return rc; return rc;
}
#endif #endif
} }