mirror of
https://github.com/fluencelabs/redis
synced 2025-04-01 15:21:03 +00:00
Merge branch 'no-appendfsync-on-rewrite'
This commit is contained in:
commit
752203d86d
30
redis.c
30
redis.c
@ -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;
|
||||||
@ -1385,7 +1386,7 @@ void backgroundRewriteDoneHandler(int statloc) {
|
|||||||
/* If append only is actually enabled... */
|
/* If append only is actually enabled... */
|
||||||
close(server.appendfd);
|
close(server.appendfd);
|
||||||
server.appendfd = fd;
|
server.appendfd = fd;
|
||||||
fsync(fd);
|
if (server.appendfsync != APPENDFSYNC_NO) aof_fsync(fd);
|
||||||
server.appendseldb = -1; /* Make sure it will issue SELECT */
|
server.appendseldb = -1; /* Make sure it will issue SELECT */
|
||||||
redisLog(REDIS_NOTICE,"The new append only file was selected for future appends.");
|
redisLog(REDIS_NOTICE,"The new append only file was selected for future appends.");
|
||||||
} else {
|
} else {
|
||||||
@ -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) {
|
|||||||
} 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;
|
||||||
@ -4209,7 +4216,7 @@ static int prepareForShutdown() {
|
|||||||
}
|
}
|
||||||
if (server.appendonly) {
|
if (server.appendonly) {
|
||||||
/* Append only file: fsync() the AOF and exit */
|
/* Append only file: fsync() the AOF and exit */
|
||||||
fsync(server.appendfd);
|
aof_fsync(server.appendfd);
|
||||||
if (server.vm_enabled) unlink(server.vm_swap_file);
|
if (server.vm_enabled) unlink(server.vm_swap_file);
|
||||||
} else {
|
} else {
|
||||||
/* Snapshotting. Perform a SYNC SAVE and exit */
|
/* Snapshotting. Perform a SYNC SAVE and exit */
|
||||||
@ -8266,6 +8273,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 ||
|
||||||
@ -8704,7 +8716,7 @@ static int rewriteAppendOnlyFile(char *filename) {
|
|||||||
|
|
||||||
/* Make sure data will not remain on the OS's output buffers */
|
/* Make sure data will not remain on the OS's output buffers */
|
||||||
fflush(fp);
|
fflush(fp);
|
||||||
fsync(fileno(fp));
|
aof_fsync(fileno(fp));
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
/* Use RENAME to make sure the DB file is changed atomically only
|
/* Use RENAME to make sure the DB file is changed atomically only
|
||||||
@ -8821,7 +8833,7 @@ static void aofRemoveTempFile(pid_t childpid) {
|
|||||||
* at runtime using the CONFIG command. */
|
* at runtime using the CONFIG command. */
|
||||||
static void stopAppendOnly(void) {
|
static void stopAppendOnly(void) {
|
||||||
flushAppendOnlyFile();
|
flushAppendOnlyFile();
|
||||||
fsync(server.appendfd);
|
aof_fsync(server.appendfd);
|
||||||
close(server.appendfd);
|
close(server.appendfd);
|
||||||
|
|
||||||
server.appendfd = -1;
|
server.appendfd = -1;
|
||||||
@ -9990,6 +10002,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);
|
||||||
@ -10105,6 +10122,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;
|
||||||
|
|
||||||
|
20
redis.conf
20
redis.conf
@ -195,6 +195,26 @@ appendonly no
|
|||||||
appendfsync everysec
|
appendfsync everysec
|
||||||
# appendfsync no
|
# appendfsync no
|
||||||
|
|
||||||
|
# When the AOF fsync policy is set to always or everysec, and a background
|
||||||
|
# saving process (a background save or AOF log background rewriting) is
|
||||||
|
# performing a lot of I/O against the disk, in some Linux configurations
|
||||||
|
# Redis may block too long on the fsync() call. Note that there is no fix for
|
||||||
|
# this currently, as even performing fsync in a different thread will block
|
||||||
|
# our synchronous write(2) call.
|
||||||
|
#
|
||||||
|
# In order to mitigate this problem it's possible to use the following option
|
||||||
|
# that will prevent fsync() from being called in the main process while a
|
||||||
|
# BGSAVE or BGREWRITEAOF is in progress.
|
||||||
|
#
|
||||||
|
# This means that while another child is saving the durability of Redis is
|
||||||
|
# the same as "appendfsync none", that in pratical terms means that it is
|
||||||
|
# possible to lost up to 30 seconds of log in the worst scenario (with the
|
||||||
|
# default Linux settings).
|
||||||
|
#
|
||||||
|
# If you have latency problems turn this to "yes". Otherwise leave it as
|
||||||
|
# "no" that is the safest pick from the point of view of durability.
|
||||||
|
no-appendfsync-on-rewrite no
|
||||||
|
|
||||||
################################ VIRTUAL MEMORY ###############################
|
################################ VIRTUAL MEMORY ###############################
|
||||||
|
|
||||||
# Virtual Memory allows Redis to work with datasets bigger than the actual
|
# Virtual Memory allows Redis to work with datasets bigger than the actual
|
||||||
|
Loading…
x
Reference in New Issue
Block a user