Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
dc98907e
Commit
dc98907e
authored
Jan 22, 2016
by
antirez
Browse files
Cluster announce ip: take myself->ip always in sync.
parent
11436b14
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
dc98907e
...
@@ -1658,7 +1658,7 @@ int clusterProcessPacket(clusterLink *link) {
...
@@ -1658,7 +1658,7 @@ int clusterProcessPacket(clusterLink *link) {
/* We use incoming MEET messages in order to set the address
/* We use incoming MEET messages in order to set the address
* for 'myself', since only other cluster nodes will send us
* for 'myself', since only other cluster nodes will send us
* MEET messag
s
es on handshakes, when the cluster joins, or
* MEET messages on handshakes, when the cluster joins, or
* later if we changed address, and those nodes will use our
* later if we changed address, and those nodes will use our
* official address to connect to us. So by obtaining this address
* official address to connect to us. So by obtaining this address
* from the socket is a simple way to discover / update our own
* from the socket is a simple way to discover / update our own
...
@@ -1667,13 +1667,12 @@ int clusterProcessPacket(clusterLink *link) {
...
@@ -1667,13 +1667,12 @@ int clusterProcessPacket(clusterLink *link) {
* However if we don't have an address at all, we update the address
* 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
* even with a normal PING packet. If it's wrong it will be fixed
* by MEET later. */
* by MEET later. */
if
(
type
==
CLUSTERMSG_TYPE_MEET
||
myself
->
ip
[
0
]
==
'\0'
)
{
if ((type == CLUSTERMSG_TYPE_MEET || myself->ip[0] == '\0') &&
server.cluster_announce_ip == NULL)
{
char ip[NET_IP_STR_LEN];
char ip[NET_IP_STR_LEN];
if
(
server
.
cluster_announce_ip
)
{
if (anetSockName(link->fd,ip,sizeof(ip),NULL) != -1 &&
strncpy
(
myself
->
ip
,
server
.
cluster_announce_ip
,
NET_IP_STR_LEN
);
myself
->
ip
[
NET_IP_STR_LEN
-
1
]
=
'\0'
;
}
else
if
(
anetSockName
(
link
->
fd
,
ip
,
sizeof
(
ip
),
NULL
)
!=
-
1
&&
strcmp(ip,myself->ip))
strcmp(ip,myself->ip))
{
{
memcpy(myself->ip,ip,NET_IP_STR_LEN);
memcpy(myself->ip,ip,NET_IP_STR_LEN);
...
@@ -3118,6 +3117,31 @@ void clusterCron(void) {
...
@@ -3118,6 +3117,31 @@ void clusterCron(void) {
iteration++; /* Number of times this function was called so far. */
iteration++; /* Number of times this function was called so far. */
/* We want to take myself->ip in sync with the cluster-announce-ip option.
* The option can be set at runtime via CONFIG SET, so we periodically check
* if the option changed to reflect this into myself->ip. */
{
static char *prev_ip = NULL;
char *curr_ip = server.cluster_announce_ip;
int changed = 0;
if (prev_ip == NULL && curr_ip != NULL) changed = 1;
if (prev_ip != NULL && curr_ip == NULL) changed = 1;
if (prev_ip && curr_ip && strcmp(prev_ip,curr_ip)) changed = 1;
if (changed) {
prev_ip = curr_ip;
if (prev_ip) prev_ip = zstrdup(prev_ip);
if (curr_ip) {
strncpy(myself->ip,server.cluster_announce_ip,NET_IP_STR_LEN);
myself->ip[NET_IP_STR_LEN-1] = '\0';
} else {
myself->ip[0] = '\0'; /* Force autodetection. */
}
}
}
/* The handshake timeout is the time after which a handshake node that was
/* The handshake timeout is the time after which a handshake node that was
* not turned into a normal node is removed from the nodes. Usually it is
* not turned into a normal node is removed from the nodes. Usually it is
* just the NODE_TIMEOUT value, but when NODE_TIMEOUT is too small we use
* just the NODE_TIMEOUT value, but when NODE_TIMEOUT is too small we use
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment