From 087f41409052da35270417c85010c6739fd28200 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 15 Dec 2011 20:03:28 +0100 Subject: [PATCH] Fix: when aof_write_rewrite is true don't append on the AOF buffer but accumulate the differences for the rewrite. --- src/aof.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/aof.c b/src/aof.c index 4d342091..15a456f9 100644 --- a/src/aof.c +++ b/src/aof.c @@ -224,15 +224,9 @@ sds catAppendOnlyExpireAtCommand(sds buf, struct redisCommand *cmd, robj *key, r } void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int argc) { - sds buf; + sds buf = sdsempty(); robj *tmpargv[3]; - /* Return ASAP if we are writing a rewrite to finish in order to start - * appending to the Append Only File. */ - if (server.aof_wait_rewrite) return; - - buf = sdsempty(); - /* The DB this command was targetting is not the same as the last command * we appendend. To issue a SELECT command is needed. */ if (dictid != server.appendseldb) { @@ -265,8 +259,15 @@ void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int a /* 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