summaryrefslogtreecommitdiff
path: root/src/config.h
diff options
context:
space:
mode:
authorguoxiang1996 <mzygdeaq@qq.com>2021-10-15 13:44:25 +0800
committerGitHub <noreply@github.com>2021-10-15 08:44:25 +0300
commit3c9e5271c6762f25af12a0d039dc23a469258ffd (patch)
tree170ddc326234c78db94a2582c6ea96e0ccf30f0a /src/config.h
parent24b67d5520ca062d2c0ed432112fd3c26ceb3daa (diff)
downloadredis-3c9e5271c6762f25af12a0d039dc23a469258ffd.tar.gz
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.
Diffstat (limited to 'src/config.h')
-rw-r--r--src/config.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/config.h b/src/config.h
index 5a4223fbd..c023265d7 100644
--- a/src/config.h
+++ b/src/config.h
@@ -31,6 +31,7 @@
#define __CONFIG_H
#ifdef __APPLE__
+#include <fcntl.h> // for fcntl(fd, F_FULLFSYNC)
#include <AvailabilityMacros.h>
#endif
@@ -97,10 +98,12 @@
#endif
/* Define redis_fsync to fdatasync() in Linux and fsync() for all the rest */
-#ifdef __linux__
-#define redis_fsync fdatasync
+#if defined(__linux__)
+#define redis_fsync(fd) fdatasync(fd)
+#elif defined(__APPLE__)
+#define redis_fsync(fd) fcntl(fd, F_FULLFSYNC)
#else
-#define redis_fsync fsync
+#define redis_fsync(fd) fsync(fd)
#endif
#if __GNUC__ >= 4
@@ -122,6 +125,8 @@
#if (defined(__linux__) && defined(SYNC_FILE_RANGE_WAIT_BEFORE))
#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)
+#elif defined(__APPLE__)
+#define rdb_fsync_range(fd,off,size) fcntl(fd, F_FULLFSYNC)
#else
#define rdb_fsync_range(fd,off,size) fsync(fd)
#endif