Unverified Commit 3c9e5271 authored by guoxiang1996's avatar guoxiang1996 Committed by GitHub
Browse files

Use fcntl(fd,F_FULLFSYNC) instead of fsync on OSX, improve power failure safety (#9545)

On MacOS calling fsync does not guarantee the cache on the disk itself is flushed. 
parent 24b67d55
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define __CONFIG_H #define __CONFIG_H
#ifdef __APPLE__ #ifdef __APPLE__
#include <fcntl.h> // for fcntl(fd, F_FULLFSYNC)
#include <AvailabilityMacros.h> #include <AvailabilityMacros.h>
#endif #endif
...@@ -97,10 +98,12 @@ ...@@ -97,10 +98,12 @@
#endif #endif
/* Define redis_fsync to fdatasync() in Linux and fsync() for all the rest */ /* Define redis_fsync to fdatasync() in Linux and fsync() for all the rest */
#ifdef __linux__ #if defined(__linux__)
#define redis_fsync fdatasync #define redis_fsync(fd) fdatasync(fd)
#elif defined(__APPLE__)
#define redis_fsync(fd) fcntl(fd, F_FULLFSYNC)
#else #else
#define redis_fsync fsync #define redis_fsync(fd) fsync(fd)
#endif #endif
#if __GNUC__ >= 4 #if __GNUC__ >= 4
...@@ -122,6 +125,8 @@ ...@@ -122,6 +125,8 @@
#if (defined(__linux__) && defined(SYNC_FILE_RANGE_WAIT_BEFORE)) #if (defined(__linux__) && defined(SYNC_FILE_RANGE_WAIT_BEFORE))
#define HAVE_SYNC_FILE_RANGE 1 #define HAVE_SYNC_FILE_RANGE 1
#define rdb_fsync_range(fd,off,size) sync_file_range(fd,off,size,SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE) #define rdb_fsync_range(fd,off,size) sync_file_range(fd,off,size,SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE)
#elif defined(__APPLE__)
#define rdb_fsync_range(fd,off,size) fcntl(fd, F_FULLFSYNC)
#else #else
#define rdb_fsync_range(fd,off,size) fsync(fd) #define rdb_fsync_range(fd,off,size) fsync(fd)
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment