summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-01-13 10:48:49 +0100
committerantirez <antirez@gmail.com>2015-01-13 10:50:34 +0100
commitcf76af6b9fb7f808ac6f0ab79393d390a14f9cd9 (patch)
tree9230202890153097d493bdd74f192ac11e798785
parent5b0f4a83ace5d44289bfc0186449611187f081f2 (diff)
downloadredis-cf76af6b9fb7f808ac6f0ab79393d390a14f9cd9.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.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/cluster.c b/src/cluster.c
index 4e42737fb..ec6901e8f 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -1547,18 +1547,20 @@ 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 &&
strcmp(ip,myself->ip))
{
memcpy(myself->ip,ip,REDIS_IP_STR_LEN);
-
- anetFormatAddr(ip, sizeof(ip), myself->ip, -1);
redisLog(REDIS_WARNING,"IP address for this node updated to %s",
- ip);
+ myself->ip);
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG);
}
}