server.appendfd = -1;
server.appendseldb = -1;
server.appendonly = 0;
+ server.aof_wait_rewrite = 0;
/* rewrite operation in progress? kill it, wait child exit */
if (server.bgrewritechildpid != -1) {
int statloc;
/* reset the buffer accumulating changes while the child saves */
sdsfree(server.bgrewritebuf);
server.bgrewritebuf = sdsempty();
+ aofRemoveTempFile(server.bgrewritechildpid);
server.bgrewritechildpid = -1;
}
}
server.lastfsync = time(NULL);
server.appendfd = open(server.appendfilename,O_WRONLY|O_APPEND|O_CREAT,0644);
if (server.appendfd == -1) {
- redisLog(REDIS_WARNING,"Used tried to switch on AOF via CONFIG, but I can't open the AOF file: %s",strerror(errno));
+ redisLog(REDIS_WARNING,"Redis needs to enable the AOF but can't open the append only file: %s",strerror(errno));
return REDIS_ERR;
}
if (rewriteAppendOnlyFileBackground() == REDIS_ERR) {
server.appendonly = 0;
close(server.appendfd);
- redisLog(REDIS_WARNING,"User tried turning on AOF with CONFIG SET but I can't trigger a background AOF rewrite operation. Check the above logs for more info about the error.");
+ redisLog(REDIS_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 REDIS_ERR;
}
+ /* We correctly switched on AOF, now wait for the rerwite to be complete
+ * in order to append data on disk. */
+ server.aof_wait_rewrite = 1;
return REDIS_OK;
}
/* Append to the AOF buffer. This will be flushed on disk just before
* of re-entering the event loop, so before the client will get a
- * positive reply about the operation performed. */
- server.aofbuf = sdscatlen(server.aofbuf,buf,sdslen(buf));
+ * positive reply about the operation performed.
+ *
+ * Note, we don't add stuff in the AOF buffer if aof_wait_rewrite is
+ * non zero, as this means we are starting with a new AOF and the
+ * current one is meaningless (this happens for instance after
+ * a slave resyncs with its master). */
+ if (!server.aof_wait_rewrite) {
+ server.aofbuf = sdscatlen(server.aofbuf,buf,sdslen(buf));
+ }
/* If a background append only file rewriting is in progress we want to
* accumulate the differences between the child DB and the current one
}
redisLog(REDIS_NOTICE, "Background AOF rewrite successful");
+ server.aof_wait_rewrite = 0;
/* Asynchronously close the overwritten AOF. */
if (oldfd != -1) bioCreateBackgroundJob(REDIS_BIO_CLOSE_FILE,(void*)(long)oldfd,NULL,NULL);
server.bgrewritebuf = sdsempty();
aofRemoveTempFile(server.bgrewritechildpid);
server.bgrewritechildpid = -1;
+ /* If we were waiting for an AOF rewrite before to start appending
+ * to the AOF again (this happens both when the user switches on
+ * AOF with CONFIG SET, and after a slave with AOF enabled syncs with
+ * the master), but the rewrite failed (otherwise aof_wait_rewrite
+ * would be zero), we need to schedule a new one. */
+ if (server.aof_wait_rewrite) server.aofrewrite_scheduled = 1;
}