summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-01-13 10:48:49 +0100
committerantirez <antirez@gmail.com>2015-01-13 16:23:48 +0100
commitdf1a7fc4fe12c4027b7dfaac39377a7644486dc9 (patch)
tree6b4b18688577b8238bc0a26f7f812cb10711f4d0
parent45e2a26ded818ca080bb0f833ddcff958227acee (diff)
downloadredis-df1a7fc4fe12c4027b7dfaac39377a7644486dc9.tar.gz
Cluster: fetch my IP even if msg is not MEET for the first time.
In order to avoid that misconfigured cluster nodes at some time may force an IP update on other nodes, it is required that nodes update their own address only on MEET messages. However it does not make sense to do this the first time a node is contacted and yet does not have an IP, we just risk that myself->ip remains not assigned if there are messages lost or cluster creation procedures that don't make sure everybody is targeted by at least one incoming MEET message. Also fix the logging of the IP switch avoiding the :-1 tail.
-rw-r--r--src/cluster.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cluster.c b/src/cluster.c
index c1af411b8..c3cf06026 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -1547,8 +1547,12 @@ int clusterProcessPacket(clusterLink *link) {
* later if we changed address, and those nodes will use our
* official address to connect to us. So by obtaining this address
* from the socket is a simple way to discover / update our own
- * address in the cluster without it being hardcoded in the config. */
- if (type == CLUSTERMSG_TYPE_MEET) {
+ * address in the cluster without it being hardcoded in the config.
+ *
+ * However if we don't have an address at all, we update the address
+ * even with a normal PING packet. If it's wrong it will be fixed
+ * by MEET later. */
+ if (type == CLUSTERMSG_TYPE_MEET || myself->ip[0] == '\0') {
char ip[REDIS_IP_STR_LEN];
if (anetSockName(link->fd,ip,sizeof(ip),NULL) != -1 &&