summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-10-15 09:59:07 +0200
committerantirez <antirez@gmail.com>2015-10-15 09:59:07 +0200
commit816dda3971b5dacb89a5a595140f31e08120ffcb (patch)
tree43eee19a9a88f3fc43aac6b0428b9b28a2e291b3
parentdb98e549823fe9d0dd39edfdbd7862d7c0164ba4 (diff)
downloadredis-816dda3971b5dacb89a5a595140f31e08120ffcb.tar.gz
Minor changes to PR #2813.
* Function to test for slave handshake renamed slaveIsInHandshakeState. * Function no longer accepts arguments since it always tests the same global state. * Test for state translated to a range test since defines are guaranteed to stay in order in the future. * Use the new function in the ROLE command implementation as well.
-rw-r--r--src/replication.c57
1 files changed, 22 insertions, 35 deletions
diff --git a/src/replication.c b/src/replication.c
index 3c642f0b7..09e0b97f8 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -41,7 +41,6 @@ void replicationDiscardCachedMaster(void);
void replicationResurrectCachedMaster(int newfd);
void replicationSendAck(void);
void putSlaveOnline(redisClient *slave);
-int serverInHandshakeState(int repl_state);
/* --------------------------- Utility functions ---------------------------- */
@@ -904,6 +903,13 @@ void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
/* ----------------------------------- SLAVE -------------------------------- */
+/* Returns 1 if the given replication state is a handshake state,
+ * 0 otherwise. */
+int slaveIsInHandshakeState(void) {
+ return server.repl_state >= REDIS_REPL_RECEIVE_PONG &&
+ server.repl_state <= REDIS_REPL_RECEIVE_PSYNC;
+}
+
/* Abort the async download of the bulk dataset while SYNC-ing with master */
void replicationAbortSyncTransfer(void) {
redisAssert(server.repl_state == REDIS_REPL_TRANSFER);
@@ -1621,7 +1627,7 @@ void undoConnectWithMaster(void) {
int fd = server.repl_transfer_s;
redisAssert(server.repl_state == REDIS_REPL_CONNECTING ||
- serverInHandshakeState(server.repl_state));
+ slaveIsInHandshakeState());
aeDeleteFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE);
close(fd);
server.repl_transfer_s = -1;
@@ -1640,7 +1646,7 @@ int cancelReplicationHandshake(void) {
if (server.repl_state == REDIS_REPL_TRANSFER) {
replicationAbortSyncTransfer();
} else if (server.repl_state == REDIS_REPL_CONNECTING ||
- serverInHandshakeState(server.repl_state))
+ slaveIsInHandshakeState())
{
undoConnectWithMaster();
} else {
@@ -1790,42 +1796,23 @@ void roleCommand(redisClient *c) {
addReplyBulkCBuffer(c,"slave",5);
addReplyBulkCString(c,server.masterhost);
addReplyLongLong(c,server.masterport);
- switch(server.repl_state) {
- case REDIS_REPL_NONE: slavestate = "none"; break;
- case REDIS_REPL_CONNECT: slavestate = "connect"; break;
- case REDIS_REPL_CONNECTING: slavestate = "connecting"; break;
- case REDIS_REPL_RECEIVE_PONG:
- case REDIS_REPL_SEND_AUTH:
- case REDIS_REPL_RECEIVE_AUTH:
- case REDIS_REPL_SEND_PORT:
- case REDIS_REPL_RECEIVE_PORT:
- case REDIS_REPL_SEND_CAPA:
- case REDIS_REPL_RECEIVE_CAPA:
- case REDIS_REPL_SEND_PSYNC:
- case REDIS_REPL_RECEIVE_PSYNC: slavestate = "handshake"; break;
- case REDIS_REPL_TRANSFER: slavestate = "sync"; break;
- case REDIS_REPL_CONNECTED: slavestate = "connected"; break;
- default: slavestate = "unknown"; break;
+ if (slaveIsInHandshakeState()) {
+ slavestate = "handshake";
+ } else {
+ switch(server.repl_state) {
+ case REDIS_REPL_NONE: slavestate = "none"; break;
+ case REDIS_REPL_CONNECT: slavestate = "connect"; break;
+ case REDIS_REPL_CONNECTING: slavestate = "connecting"; break;
+ case REDIS_REPL_TRANSFER: slavestate = "sync"; break;
+ case REDIS_REPL_CONNECTED: slavestate = "connected"; break;
+ default: slavestate = "unknown"; break;
+ }
}
addReplyBulkCString(c,slavestate);
addReplyLongLong(c,server.master ? server.master->reploff : -1);
}
}
-/* Returns 1 if the given replication state is a handshake state,
- * 0 otherwise. */
-int serverInHandshakeState(int repl_state) {
- return repl_state == REDIS_REPL_RECEIVE_PONG ||
- repl_state == REDIS_REPL_SEND_AUTH ||
- repl_state == REDIS_REPL_RECEIVE_AUTH ||
- repl_state == REDIS_REPL_SEND_PORT ||
- repl_state == REDIS_REPL_RECEIVE_PORT ||
- repl_state == REDIS_REPL_SEND_CAPA ||
- repl_state == REDIS_REPL_RECEIVE_CAPA ||
- repl_state == REDIS_REPL_SEND_PSYNC ||
- repl_state == REDIS_REPL_RECEIVE_PSYNC;
-}
-
/* Send a REPLCONF ACK command to the master to inform it about the current
* processed offset. If we are not connected with a master, the command has
* no effects. */
@@ -2061,8 +2048,8 @@ void replicationCron(void) {
/* Non blocking connection timeout? */
if (server.masterhost &&
(server.repl_state == REDIS_REPL_CONNECTING ||
- serverInHandshakeState(server.repl_state)) &&
- (time(NULL)-server.repl_transfer_lastio) > server.repl_timeout)
+ slaveIsInHandshakeState()) &&
+ (time(NULL)-server.repl_transfer_lastio) > server.repl_timeout)
{
redisLog(REDIS_WARNING,"Timeout connecting to the MASTER...");
undoConnectWithMaster();