X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/1844f9900f131a538d1cee988d76ef689c8426fe..b80b1c5914435c3a013cfe9b19e39f9de35ab06e:/src/replication.c?ds=sidebyside diff --git a/src/replication.c b/src/replication.c index e08517e8..dd42fcf1 100644 --- a/src/replication.c +++ b/src/replication.c @@ -122,8 +122,7 @@ void syncCommand(redisClient *c) { if (ln) { /* Perfect, the server is already registering differences for * another slave. Set the right state, and copy the buffer. */ - listRelease(c->reply); - c->reply = listDup(slave->reply); + copyClientOutputBuffer(c,slave); c->replstate = REDIS_REPL_WAIT_BGSAVE_END; redisLog(REDIS_NOTICE,"Waiting for end of BGSAVE for SYNC"); } else { @@ -518,9 +517,23 @@ void slaveofCommand(redisClient *c) { redisLog(REDIS_NOTICE,"MASTER MODE enabled (user request)"); } } else { + long port; + + if ((getLongFromObjectOrReply(c, c->argv[2], &port, NULL) != REDIS_OK)) + return; + + /* Check if we are already attached to the specified slave */ + if (server.masterhost && !strcasecmp(server.masterhost,c->argv[1]->ptr) + && server.masterport == port) { + redisLog(REDIS_NOTICE,"SLAVE OF would result into synchronization with the master we are already connected with. No operation performed."); + addReplySds(c,sdsnew("+OK Already connected to specified master\r\n")); + return; + } + /* There was no previous master or the user specified a different one, + * we can continue. */ sdsfree(server.masterhost); server.masterhost = sdsdup(c->argv[1]->ptr); - server.masterport = atoi(c->argv[2]->ptr); + server.masterport = port; if (server.master) freeClient(server.master); if (server.repl_state == REDIS_REPL_TRANSFER) replicationAbortSyncTransfer();