mirror of
https://github.com/fluencelabs/redis
synced 2025-03-25 03:41:04 +00:00
Sentinel: parse new INFO replication output correctly.
Sentinel was not able to detect slaves when connected to a very recent version of Redis master since a previos non-backward compatible change to INFO broken the parsing of the slaves ip:port INFO output. This fixes issue #1164
This commit is contained in:
parent
b02bb47e67
commit
4c0f8c4e5a
@ -1397,20 +1397,33 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* slave0:<ip>,<port>,<state> */
|
/* old versions: slave0:<ip>,<port>,<state>
|
||||||
|
* new versions: slave0:ip=127.0.0.1,port=9999,... */
|
||||||
if ((ri->flags & SRI_MASTER) &&
|
if ((ri->flags & SRI_MASTER) &&
|
||||||
sdslen(l) >= 7 &&
|
sdslen(l) >= 7 &&
|
||||||
!memcmp(l,"slave",5) && isdigit(l[5]))
|
!memcmp(l,"slave",5) && isdigit(l[5]))
|
||||||
{
|
{
|
||||||
char *ip, *port, *end;
|
char *ip, *port, *end;
|
||||||
|
|
||||||
ip = strchr(l,':'); if (!ip) continue;
|
if (strstr(l,"ip=") == NULL) {
|
||||||
ip++; /* Now ip points to start of ip address. */
|
/* Old format. */
|
||||||
port = strchr(ip,','); if (!port) continue;
|
ip = strchr(l,':'); if (!ip) continue;
|
||||||
*port = '\0'; /* nul term for easy access. */
|
ip++; /* Now ip points to start of ip address. */
|
||||||
port++; /* Now port points to start of port number. */
|
port = strchr(ip,','); if (!port) continue;
|
||||||
end = strchr(port,','); if (!end) continue;
|
*port = '\0'; /* nul term for easy access. */
|
||||||
*end = '\0'; /* nul term for easy access. */
|
port++; /* Now port points to start of port number. */
|
||||||
|
end = strchr(port,','); if (!end) continue;
|
||||||
|
*end = '\0'; /* nul term for easy access. */
|
||||||
|
} else {
|
||||||
|
/* New format. */
|
||||||
|
ip = strstr(l,"ip="); if (!ip) continue;
|
||||||
|
ip += 3; /* Now ip points to start of ip address. */
|
||||||
|
port = strstr(l,"port="); if (!port) continue;
|
||||||
|
port += 5; /* Now port points to start of port number. */
|
||||||
|
/* Nul term both fields for easy access. */
|
||||||
|
end = strchr(ip,','); if (end) *end = '\0';
|
||||||
|
end = strchr(port,','); if (end) *end = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if we already have this slave into our table,
|
/* Check if we already have this slave into our table,
|
||||||
* otherwise add it. */
|
* otherwise add it. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user