Commit 38db9171 authored by antirez's avatar antirez
Browse files

added new option no-appendfsync-on-rewrite to avoid blocking on fsync() in the...

added new option no-appendfsync-on-rewrite to avoid blocking on fsync() in the main thread while a background process is doing big I/O
parent 8a3b0d2d
...@@ -369,6 +369,7 @@ struct redisServer { ...@@ -369,6 +369,7 @@ struct redisServer {
int daemonize; int daemonize;
int appendonly; int appendonly;
int appendfsync; int appendfsync;
int no_appendfsync_on_rewrite;
int shutdown_asap; int shutdown_asap;
time_t lastfsync; time_t lastfsync;
int appendfd; int appendfd;
...@@ -1685,6 +1686,7 @@ static void initServerConfig() { ...@@ -1685,6 +1686,7 @@ static void initServerConfig() {
server.daemonize = 0; server.daemonize = 0;
server.appendonly = 0; server.appendonly = 0;
server.appendfsync = APPENDFSYNC_EVERYSEC; server.appendfsync = APPENDFSYNC_EVERYSEC;
server.no_appendfsync_on_rewrite = 0;
server.lastfsync = time(NULL); server.lastfsync = time(NULL);
server.appendfd = -1; server.appendfd = -1;
server.appendseldb = -1; /* Make sure the first time will not match */ server.appendseldb = -1; /* Make sure the first time will not match */
...@@ -1941,6 +1943,11 @@ static void loadServerConfig(char *filename) { ...@@ -1941,6 +1943,11 @@ static void loadServerConfig(char *filename) {
} else if (!strcasecmp(argv[0],"appendfilename") && argc == 2) { } else if (!strcasecmp(argv[0],"appendfilename") && argc == 2) {
zfree(server.appendfilename); zfree(server.appendfilename);
server.appendfilename = zstrdup(argv[1]); server.appendfilename = zstrdup(argv[1]);
} else if (!strcasecmp(argv[0],"no-appendfsync-on-rewrite")
&& argc == 2) {
if ((server.no_appendfsync_on_rewrite= yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"appendfsync") && argc == 2) { } else if (!strcasecmp(argv[0],"appendfsync") && argc == 2) {
if (!strcasecmp(argv[1],"no")) { if (!strcasecmp(argv[1],"no")) {
server.appendfsync = APPENDFSYNC_NO; server.appendfsync = APPENDFSYNC_NO;
...@@ -8236,6 +8243,11 @@ static void flushAppendOnlyFile(void) { ...@@ -8236,6 +8243,11 @@ static void flushAppendOnlyFile(void) {
sdsfree(server.aofbuf); sdsfree(server.aofbuf);
server.aofbuf = sdsempty(); server.aofbuf = sdsempty();
/* Don't Fsync if no-appendfsync-on-rewrite is set to yes and we have
* childs performing heavy I/O on disk. */
if (server.no_appendfsync_on_rewrite &&
(server.bgrewritechildpid != -1 || server.bgsavechildpid != -1))
return;
/* Fsync if needed */ /* Fsync if needed */
now = time(NULL); now = time(NULL);
if (server.appendfsync == APPENDFSYNC_ALWAYS || if (server.appendfsync == APPENDFSYNC_ALWAYS ||
...@@ -9960,6 +9972,11 @@ static void configSetCommand(redisClient *c) { ...@@ -9960,6 +9972,11 @@ static void configSetCommand(redisClient *c) {
} else { } else {
goto badfmt; goto badfmt;
} }
} else if (!strcasecmp(c->argv[2]->ptr,"no-appendfsync-on-rewrite")) {
int yn = yesnotoi(o->ptr);
if (yn == -1) goto badfmt;
server.no_appendfsync_on_rewrite = yn;
} else if (!strcasecmp(c->argv[2]->ptr,"appendonly")) { } else if (!strcasecmp(c->argv[2]->ptr,"appendonly")) {
int old = server.appendonly; int old = server.appendonly;
int new = yesnotoi(o->ptr); int new = yesnotoi(o->ptr);
...@@ -10075,6 +10092,11 @@ static void configGetCommand(redisClient *c) { ...@@ -10075,6 +10092,11 @@ static void configGetCommand(redisClient *c) {
addReplyBulkCString(c,server.appendonly ? "yes" : "no"); addReplyBulkCString(c,server.appendonly ? "yes" : "no");
matches++; matches++;
} }
if (stringmatch(pattern,"no-appendfsync-on-rewrite",0)) {
addReplyBulkCString(c,"no-appendfsync-on-rewrite");
addReplyBulkCString(c,server.no_appendfsync_on_rewrite ? "yes" : "no");
matches++;
}
if (stringmatch(pattern,"appendfsync",0)) { if (stringmatch(pattern,"appendfsync",0)) {
char *policy; char *policy;
......
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