summaryrefslogtreecommitdiff
path: root/src/aof.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-07-21 18:34:53 +0200
committerantirez <antirez@gmail.com>2016-07-21 18:35:01 +0200
commit0a628e51025c4307c70cb00094dff9cdd1732f31 (patch)
tree219d203ed2db235d860f56cbda3367001faf272f /src/aof.c
parent780a8b1d766daa6504f701bf09f6a4938179ba66 (diff)
downloadredis-0a628e51025c4307c70cb00094dff9cdd1732f31.tar.gz
Avoid simultaneous RDB and AOF child process.
This patch, written in collaboration with Oran Agra (@oranagra) is a companion to 780a8b1. Together the two patches should avoid that the AOF and RDB saving processes can be spawned at the same time. Previously conditions that could lead to two saving processes at the same time were: 1. When AOF is enabled via CONFIG SET and an RDB saving process is already active. 2. When the SYNC command decides to start an RDB saving process ASAP in order to serve a new slave that cannot partially resynchronize (but only if we have a disk target for replication, for diskless replication there is not such a problem). Condition "1" is not very severe but "2" can happen often and is definitely good at degrading Redis performances in an unexpected way. The two commits have the effect of always spawning RDB savings for replication in replicationCron() instead of attempting to start an RDB save synchronously. Moreover when a BGSAVE or AOF rewrite must be performed, they are instead just postponed using flags that will try to perform such operations ASAP. Finally the BGSAVE command was modified in order to accept a SCHEDULE option so that if an AOF rewrite is in progress, when this option is given, the command no longer returns an error, but instead schedules an RDB rewrite operation for when it will be possible to start it.
Diffstat (limited to 'src/aof.c')
-rw-r--r--src/aof.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/aof.c b/src/aof.c
index aa726d33b..6a92a0cd9 100644
--- a/src/aof.c
+++ b/src/aof.c
@@ -251,7 +251,10 @@ int startAppendOnly(void) {
strerror(errno));
return C_ERR;
}
- if (rewriteAppendOnlyFileBackground() == C_ERR) {
+ if (server.rdb_child_pid != -1) {
+ server.aof_rewrite_scheduled = 1;
+ serverLog(LL_WARNING,"AOF was enabled but there is already a child process saving an RDB file on disk. An AOF background was scheduled to start when possible.");
+ } else if (rewriteAppendOnlyFileBackground() == C_ERR) {
close(server.aof_fd);
serverLog(LL_WARNING,"Redis needs to enable the AOF but can't trigger a background AOF rewrite operation. Check the above logs for more info about the error.");
return C_ERR;
@@ -1273,7 +1276,7 @@ int rewriteAppendOnlyFileBackground(void) {
pid_t childpid;
long long start;
- if (server.aof_child_pid != -1) return C_ERR;
+ if (server.aof_child_pid != -1 || server.rdb_child_pid != -1) return C_ERR;
if (aofCreatePipes() != C_OK) return C_ERR;
start = ustime();
if ((childpid = fork()) == 0) {