mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
Cluster: myself->ip autodiscovery.
Instead of having an hardcoded IP address in the node configuration, we autodiscover it via MEET messages for automatic update when the node is restarted with a different IP address. This mechanism was discussed in the context of PR #1782.
This commit is contained in:
parent
46319094db
commit
f29b12d0bf
@ -466,6 +466,11 @@ void clusterInit(void) {
|
|||||||
|
|
||||||
/* The slots -> keys map is a sorted set. Init it. */
|
/* The slots -> keys map is a sorted set. Init it. */
|
||||||
server.cluster->slots_to_keys = zslCreate();
|
server.cluster->slots_to_keys = zslCreate();
|
||||||
|
|
||||||
|
/* Set myself->port to my listening port, we'll just need to discover
|
||||||
|
* the IP address via MEET messages. */
|
||||||
|
myself->port = server.port;
|
||||||
|
|
||||||
resetManualFailover();
|
resetManualFailover();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1531,6 +1536,26 @@ int clusterProcessPacket(clusterLink *link) {
|
|||||||
if (type == CLUSTERMSG_TYPE_PING || type == CLUSTERMSG_TYPE_MEET) {
|
if (type == CLUSTERMSG_TYPE_PING || type == CLUSTERMSG_TYPE_MEET) {
|
||||||
redisLog(REDIS_DEBUG,"Ping packet received: %p", (void*)link->node);
|
redisLog(REDIS_DEBUG,"Ping packet received: %p", (void*)link->node);
|
||||||
|
|
||||||
|
/* We use incoming MEET messages in order to set the address
|
||||||
|
* for 'myself', since only other cluster nodes will send us
|
||||||
|
* MEET messagses on handshakes, when the cluster joins, or
|
||||||
|
* 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) {
|
||||||
|
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);
|
||||||
|
redisLog(REDIS_WARNING,"IP address for this node updated to %s",
|
||||||
|
myself->ip);
|
||||||
|
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Add this node if it is new for us and the msg type is MEET.
|
/* Add this node if it is new for us and the msg type is MEET.
|
||||||
* In this stage we don't try to add the node with the right
|
* In this stage we don't try to add the node with the right
|
||||||
* flags, slaveof pointer, and so forth, as this details will be
|
* flags, slaveof pointer, and so forth, as this details will be
|
||||||
|
Loading…
x
Reference in New Issue
Block a user