summaryrefslogtreecommitdiff
path: root/src/replication.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/replication.c')
-rwxr-xr-xsrc/replication.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/replication.c b/src/replication.c
index 0a4321095..9c6d4dff7 100755
--- a/src/replication.c
+++ b/src/replication.c
@@ -75,7 +75,7 @@ void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc) {
if (slave->replstate == REDIS_REPL_WAIT_BGSAVE_START) continue;
/* Feed slaves that are waiting for the initial SYNC (so these commands
- * are queued in the output buffer until the intial SYNC completes),
+ * are queued in the output buffer until the initial SYNC completes),
* or are already in sync with the master. */
if (slave->slaveseldb != dictid) {
robj *selectcmd;
@@ -202,7 +202,7 @@ void syncnowCommand(redisClient *c) {
void syncCommand(redisClient *c) {
int bgsave_required = 1;
- /* ignore SYNC if aleady slave or in monitor mode */
+ /* ignore SYNC if already slave or in monitor mode */
if (c->flags & REDIS_SLAVE) return;
/* Refuse SYNC requests if we are a slave but the link with our master
@@ -333,7 +333,7 @@ void sendBulkToSlave(aeEventLoop *el, int fd, void *privdata, int mask) {
if (slave->repldboff == 0) {
/* Write the bulk write count before to transfer the DB. In theory here
* we don't know how much room there is in the output buffer of the
- * socket, but in pratice SO_SNDLOWAT (the minimum count for output
+ * socket, but in practice SO_SNDLOWAT (the minimum count for output
* operations) will never be smaller than the few bytes we need. */
sds bulkcount;
@@ -376,7 +376,7 @@ void sendBulkToSlave(aeEventLoop *el, int fd, void *privdata, int mask) {
}
}
-/* This function is called at the end of every backgrond saving.
+/* This function is called at the end of every background saving.
* The argument bgsaveerr is REDIS_OK if the background saving succeeded
* otherwise REDIS_ERR is passed to the function.
*
@@ -567,7 +567,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
stopAppendOnly();
while (retry-- && startAppendOnly() == REDIS_ERR) {
- redisLog(REDIS_WARNING,"Failed enabling the AOF after successful master synchrnization! Trying it again in one second.");
+ redisLog(REDIS_WARNING,"Failed enabling the AOF after successful master synchronization! Trying it again in one second.");
sleep(1);
}
if (!retry) {
@@ -817,6 +817,27 @@ void undoConnectWithMaster(void) {
server.repl_state = REDIS_REPL_CONNECT;
}
+/* This function aborts a non blocking replication attempt if there is one
+ * in progress, by canceling the non-blocking connect attempt or
+ * the initial bulk transfer.
+ *
+ * If there was a replication handshake in progress 1 is returned and
+ * the replication state (server.repl_state) set to REDIS_REPL_CONNECT.
+ *
+ * Otherwise zero is returned and no operation is perforemd at all. */
+int cancelReplicationHandshake(void) {
+ if (server.repl_state == REDIS_REPL_TRANSFER) {
+ replicationAbortSyncTransfer();
+ } else if (server.repl_state == REDIS_REPL_CONNECTING ||
+ server.repl_state == REDIS_REPL_RECEIVE_PONG)
+ {
+ undoConnectWithMaster();
+ } else {
+ return 0;
+ }
+ return 1;
+}
+
void slaveofCommand(redisClient *c) {
if (!strcasecmp(c->argv[1]->ptr,"no") &&
!strcasecmp(c->argv[2]->ptr,"one")) {
@@ -824,11 +845,7 @@ void slaveofCommand(redisClient *c) {
sdsfree(server.masterhost);
server.masterhost = NULL;
if (server.master) freeClient(server.master);
- if (server.repl_state == REDIS_REPL_TRANSFER)
- replicationAbortSyncTransfer();
- else if (server.repl_state == REDIS_REPL_CONNECTING ||
- server.repl_state == REDIS_REPL_RECEIVE_PONG)
- undoConnectWithMaster();
+ cancelReplicationHandshake();
server.repl_state = REDIS_REPL_NONE;
redisLog(REDIS_NOTICE,"MASTER MODE enabled (user request)");
}
@@ -852,8 +869,7 @@ void slaveofCommand(redisClient *c) {
server.masterport = port;
if (server.master) freeClient(server.master);
disconnectSlaves(); /* Force our slaves to resync with us as well. */
- if (server.repl_state == REDIS_REPL_TRANSFER)
- replicationAbortSyncTransfer();
+ cancelReplicationHandshake();
server.repl_state = REDIS_REPL_CONNECT;
redisLog(REDIS_NOTICE,"SLAVE OF %s:%d enabled (user request)",
server.masterhost, server.masterport);