Skip to content
Browse files

fsync always now uses O_DIRECT on Linux

  • Loading branch information...
1 parent d3277ec commit 566c3c7a22c0ec217c40f7a95db2bb83c8cc16c7 @antirez committed Apr 20, 2010
Showing with 15 additions and 1 deletion.
  1. +5 −0 config.h
  2. +10 −1 redis.c
View
5 config.h
@@ -35,4 +35,9 @@
#define HAVE_KQUEUE 1
#endif
+/* test for O_DIRECT */
+#ifdef __linux__
+#define HAVE_O_DIRECT 1
+#endif
+
#endif
View
11 redis.c
@@ -1673,7 +1673,16 @@ static void initServer() {
acceptHandler, NULL) == AE_ERR) oom("creating file event");
if (server.appendonly) {
- server.appendfd = open(server.appendfilename,O_WRONLY|O_APPEND|O_CREAT,0644);
+ int flags = O_WRONLY|O_APPEND|O_CREAT;
+
+#ifdef HAVE_O_DIRECT
+ if (server.appendfsync == APPENDFSYNC_ALWAYS) {
+ flags |= O_DIRECT;
+ server.appendfsync = APPENDFSYNC_NO;
+ }
+#endif
+
+ server.appendfd = open(server.appendfilename,flags,0644);
if (server.appendfd == -1) {
redisLog(REDIS_WARNING, "Can't open the append-only file: %s",
strerror(errno));

0 comments on commit 566c3c7

Please sign in to comment.
Something went wrong with that request. Please try again.