From 8e390a62ad3b06e0f11813d0c832721f0b676d63 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 16 Dec 2016 17:48:33 +0100 Subject: [PATCH] Hopefully improve code comments for issue #3616. This commit also contains other changes in order to conform the code to the Redis core style, specifically 80 chars max per line, smart conditionals in the same line: if (that) do_this(); --- src/replication.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/replication.c b/src/replication.c index f26c142a..df2e23f3 100644 --- a/src/replication.c +++ b/src/replication.c @@ -1241,14 +1241,16 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { if (eof_reached) { int aof_is_enabled = server.aof_state != AOF_OFF; + if (rename(server.repl_transfer_tmpfile,server.rdb_filename) == -1) { serverLog(LL_WARNING,"Failed trying to rename the temp DB into dump.rdb in MASTER <-> SLAVE synchronization: %s", strerror(errno)); cancelReplicationHandshake(); return; } serverLog(LL_NOTICE, "MASTER <-> SLAVE sync: Flushing old data"); - if(aof_is_enabled) /* we need to stop any AOFRW fork before flusing and parsing RDB, otherwise we'll create a CoW disaster */ - stopAppendOnly(); + /* We need to stop any AOFRW fork before flusing and parsing + * RDB, otherwise we'll create a copy-on-write disaster. */ + if(aof_is_enabled) stopAppendOnly(); signalFlushedDb(-1); emptyDb( -1, @@ -1264,8 +1266,9 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { if (rdbLoad(server.rdb_filename,&rsi) != C_OK) { serverLog(LL_WARNING,"Failed trying to load the MASTER synchronization DB from disk"); cancelReplicationHandshake(); - if (aof_is_enabled) /* re-enable so that on the next attempt, we can detect that AOF was enabled */ - restartAOF(); + /* Re-enable the AOF if we disabled it earlier, in order to restore + * the original configuration. */ + if (aof_is_enabled) restartAOF(); return; } /* Final setup of the connected slave <- master link */ @@ -1289,10 +1292,8 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { /* Restart the AOF subsystem now that we finished the sync. This * will trigger an AOF rewrite, and when done will start appending * to the new file. */ - if (aof_is_enabled) - restartAOF(); + if (aof_is_enabled) restartAOF(); } - return; error: