X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/632e4c09acad87b999dd944413ac5b75207de571..e41677b4cf1452c276e5a02e791585a25e02f8f2:/src/replication.c diff --git a/src/replication.c b/src/replication.c index c8ebb6e7..712af110 100644 --- a/src/replication.c +++ b/src/replication.c @@ -358,6 +358,8 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) { server.master->authenticated = 1; server.replstate = REDIS_REPL_CONNECTED; redisLog(REDIS_NOTICE, "MASTER <-> SLAVE sync: Finished with success"); + /* Rewrite the AOF file now that the dataset changed. */ + if (server.appendonly) rewriteAppendOnlyFileBackground(); } return; @@ -374,10 +376,18 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) { REDIS_NOTUSED(privdata); REDIS_NOTUSED(mask); + /* If this event fired after the user turned the instance into a master + * with SLAVEOF NO ONE we must just return ASAP. */ + if (server.replstate == REDIS_REPL_NONE) { + close(fd); + return; + } + + redisLog(REDIS_NOTICE,"Non blocking connect for SYNC fired the event."); /* This event should only be triggered once since it is used to have a * non-blocking connect(2) to the master. It has been triggered when this * function is called, so we can delete it. */ - aeDeleteFileEvent(server.el,fd,AE_WRITABLE); + aeDeleteFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE); /* AUTH with the master if required. */ if(server.masterauth) { @@ -453,7 +463,7 @@ int connectWithMaster(void) { return REDIS_ERR; } - if (aeCreateFileEvent(server.el,fd,AE_WRITABLE,syncWithMaster,NULL) == + if (aeCreateFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE,syncWithMaster,NULL) == AE_ERR) { close(fd); @@ -494,13 +504,10 @@ void slaveofCommand(redisClient *c) { /* --------------------------- REPLICATION CRON ---------------------------- */ -#define REDIS_REPL_TIMEOUT 60 -#define REDIS_REPL_PING_SLAVE_PERIOD 10 - void replicationCron(void) { /* Bulk transfer I/O timeout? */ if (server.masterhost && server.replstate == REDIS_REPL_TRANSFER && - (time(NULL)-server.repl_transfer_lastio) > REDIS_REPL_TIMEOUT) + (time(NULL)-server.repl_transfer_lastio) > server.repl_timeout) { redisLog(REDIS_WARNING,"Timeout receiving bulk data from MASTER..."); replicationAbortSyncTransfer(); @@ -508,7 +515,7 @@ void replicationCron(void) { /* Timed out master when we are an already connected slave? */ if (server.masterhost && server.replstate == REDIS_REPL_CONNECTED && - (time(NULL)-server.master->lastinteraction) > REDIS_REPL_TIMEOUT) + (time(NULL)-server.master->lastinteraction) > server.repl_timeout) { redisLog(REDIS_WARNING,"MASTER time out: no data nor PING received..."); freeClient(server.master); @@ -519,7 +526,6 @@ void replicationCron(void) { redisLog(REDIS_NOTICE,"Connecting to MASTER..."); if (connectWithMaster() == REDIS_OK) { redisLog(REDIS_NOTICE,"MASTER <-> SLAVE sync started"); - if (server.appendonly) rewriteAppendOnlyFileBackground(); } } @@ -527,7 +533,7 @@ void replicationCron(void) { * So slaves can implement an explicit timeout to masters, and will * be able to detect a link disconnection even if the TCP connection * will not actually go down. */ - if (!(server.cronloops % (REDIS_REPL_PING_SLAVE_PERIOD*10))) { + if (!(server.cronloops % (server.repl_ping_slave_period*10))) { listIter li; listNode *ln;