mdbx: add MDBX_OSX_SPEED_OR_DURABILITY build-time #define for MacOS.

This commit is contained in:
Leonid Yuriev 2019-08-20 02:45:03 +03:00
parent ccbf3a2bcf
commit 657d37c9e3
2 changed files with 15 additions and 2 deletions

View File

@ -23,6 +23,12 @@
# undef NDEBUG # undef NDEBUG
#endif #endif
#define MDBX_OSX_WANNA_DURABILITY 0 /* using fcntl(F_FULLFSYNC) with 5-10 times slowdown */
#define MDBX_OSX_WANNA_SPEED 1 /* using fsync() with chance of data lost on power failure */
#ifndef MDBX_OSX_SPEED_OR_DURABILITY
#define MDBX_OSX_SPEED_OR_DURABILITY MDBX_OSX_WANNA_DURABILITY
#endif
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Should be defined before any includes */ /* Should be defined before any includes */

View File

@ -668,7 +668,8 @@ int mdbx_filesync(mdbx_filehandle_t fd, enum mdbx_syncmode_bits mode_bits) {
: GetLastError(); : GetLastError();
#else #else
#ifdef __APPLE__ #if defined(__APPLE__) && \
MDBX_OSX_SPEED_OR_DURABILITY == MDBX_OSX_WANNA_DURABILITY
if (mode_bits & MDBX_SYNC_IODQ) if (mode_bits & MDBX_SYNC_IODQ)
return likely(fcntl(fd, F_FULLFSYNC) != -1) ? MDBX_SUCCESS : errno; return likely(fcntl(fd, F_FULLFSYNC) != -1) ? MDBX_SUCCESS : errno;
#endif /* MacOS */ #endif /* MacOS */
@ -788,7 +789,13 @@ int mdbx_msync(mdbx_mmap_t *map, size_t offset, size_t length, int async) {
return GetLastError(); return GetLastError();
#else #else
const int mode = async ? MS_ASYNC : MS_SYNC; const int mode = async ? MS_ASYNC : MS_SYNC;
return (msync(ptr, length, mode) == 0) ? MDBX_SUCCESS : errno; int rc = (msync(ptr, length, mode) == 0) ? MDBX_SUCCESS : errno;
#if defined(__APPLE__) && \
MDBX_OSX_SPEED_OR_DURABILITY == MDBX_OSX_WANNA_DURABILITY
if (rc == MDBX_SUCCESS && mode == MS_SYNC)
rc = likely(fcntl(map->fd, F_FULLFSYNC) != -1) ? MDBX_SUCCESS : errno;
#endif /* MacOS */
return rc;
#endif #endif
} }