diff options
author | Salvatore Sanfilippo <antirez@gmail.com> | 2016-12-16 17:43:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-16 17:43:20 +0100 |
commit | ca4ca5073e394cca3f5c8f8c508803a6d9b2c606 (patch) | |
tree | 53d803b0ec0a2f496e2fa09322a638a3a056292a | |
parent | 151af731181caf0429b4b172493c4604c6673cae (diff) | |
parent | e3a61950a212a5e603234f4009e1ec3801d5a423 (diff) | |
download | redis-ca4ca5073e394cca3f5c8f8c508803a6d9b2c606.tar.gz |
Merge pull request #3616 from oranagra/stop_aofrw_before_rdbload
CoW improvement, stop AOFRW before flushing and parsing slave RDB
-rw-r--r-- | src/replication.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/replication.c b/src/replication.c index 94287f9d0..f26c142a9 100644 --- a/src/replication.c +++ b/src/replication.c @@ -1087,6 +1087,18 @@ void replicationCreateMasterClient(int fd, int dbid) { if (dbid != -1) selectDb(server.master,dbid); } +void restartAOF() { + int retry = 10; + while (retry-- && startAppendOnly() == C_ERR) { + serverLog(LL_WARNING,"Failed enabling the AOF after successful master synchronization! Trying it again in one second."); + sleep(1); + } + if (!retry) { + serverLog(LL_WARNING,"FATAL: this slave instance finished the synchronization with its master, but the AOF can't be turned on. Exiting now."); + exit(1); + } +} + /* Asynchronously read the SYNC payload we receive from a master */ #define REPL_MAX_WRITTEN_BEFORE_FSYNC (1024*1024*8) /* 8 MB */ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { @@ -1228,12 +1240,15 @@ 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(); signalFlushedDb(-1); emptyDb( -1, @@ -1249,6 +1264,8 @@ 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(); return; } /* Final setup of the connected slave <- master link */ @@ -1272,19 +1289,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 (server.aof_state != AOF_OFF) { - int retry = 10; - - stopAppendOnly(); - while (retry-- && startAppendOnly() == C_ERR) { - serverLog(LL_WARNING,"Failed enabling the AOF after successful master synchronization! Trying it again in one second."); - sleep(1); - } - if (!retry) { - serverLog(LL_WARNING,"FATAL: this slave instance finished the synchronization with its master, but the AOF can't be turned on. Exiting now."); - exit(1); - } - } + if (aof_is_enabled) + restartAOF(); } return; |