summaryrefslogtreecommitdiff
path: root/src/redis.h
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-08-31 15:32:57 +0200
committerantirez <antirez@gmail.com>2012-09-02 12:24:38 +0200
commitbb66fc312036e444a950df27dd7cb2e3db6b4b05 (patch)
treedfaa174440b199abf08c054eb103cfa887a25b6b /src/redis.h
parente323635c2d9d9039442cd1014932e4dd314d2d06 (diff)
downloadredis-bb66fc312036e444a950df27dd7cb2e3db6b4b05.tar.gz
Send an async PING before starting replication with master.
During the first synchronization step of the replication process, a Redis slave connects with the master in a non blocking way. However once the connection is established the replication continues sending the REPLCONF command, and sometimes the AUTH command if needed. Those commands are send in a partially blocking way (blocking with timeout in the order of seconds). Because it is common for a blocked master to accept connections even if it is actually not able to reply to the slave requests, it was easy for a slave to block if the master had serious issues, but was still able to accept connections in the listening socket. For this reason we now send an asynchronous PING request just after the non blocking connection ended in a successful way, and wait for the reply before to continue with the replication process. It is very unlikely that a master replying to PING can't reply to the other commands. This solution was proposed by Didier Spezia (Thanks!) so that we don't need to turn all the replication process into a non blocking affair, but still the probability of a slave blocked is minimal even in the event of a failing master. Also we now use getsockopt(SO_ERROR) in order to check errors ASAP in the event handler, instead of waiting for actual I/O to return an error. This commit fixes issue #632.
Diffstat (limited to 'src/redis.h')
-rw-r--r--src/redis.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/redis.h b/src/redis.h
index 2641aeae9..34afd0f88 100644
--- a/src/redis.h
+++ b/src/redis.h
@@ -167,8 +167,9 @@
#define REDIS_REPL_NONE 0 /* No active replication */
#define REDIS_REPL_CONNECT 1 /* Must connect to master */
#define REDIS_REPL_CONNECTING 2 /* Connecting to master */
-#define REDIS_REPL_TRANSFER 3 /* Receiving .rdb from master */
-#define REDIS_REPL_CONNECTED 4 /* Connected to master */
+#define REDIS_REPL_RECEIVE_PONG 3 /* Wait for PING reply */
+#define REDIS_REPL_TRANSFER 4 /* Receiving .rdb from master */
+#define REDIS_REPL_CONNECTED 5 /* Connected to master */
/* Synchronous read timeout - slave side */
#define REDIS_REPL_SYNCIO_TIMEOUT 5