summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-10-15 09:59:07 +0200
committerantirez <antirez@gmail.com>2015-10-15 10:22:13 +0200
commit6ef80f4ed21c14a879166a96dda91733a48d895c (patch)
tree32844b9c8d47d052b539a186c8840c79cd9a81f7
parentdc03e4c51b6ec1cccaaa0a76f61832e499f5871b (diff)
downloadredis-6ef80f4ed21c14a879166a96dda91733a48d895c.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 e6b64d729..b3ff458a5 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 ---------------------------- */
@@ -910,6 +909,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);
@@ -1628,7 +1634,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;
@@ -1647,7 +1653,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 {
@@ -1782,42 +1788,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. */
@@ -2202,8 +2189,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();