mirror of https://mirror.osredm.com/root/redis.git
Fix sentinel issue if replica changes IP (#11590)
As Sentinel supports dynamic IP only when using hostnames, there are few leftover addess comparison logic that doesn't take into account that the IP might get change. Co-authored-by: moticless <moticless@github.com>
This commit is contained in:
parent
049f5d87e3
commit
4a27aa4875
|
@ -598,11 +598,6 @@ void releaseSentinelAddr(sentinelAddr *sa) {
|
||||||
zfree(sa);
|
zfree(sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return non-zero if two addresses are equal. */
|
|
||||||
int sentinelAddrIsEqual(sentinelAddr *a, sentinelAddr *b) {
|
|
||||||
return a->port == b->port && !strcasecmp(a->ip,b->ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return non-zero if the two addresses are equal, either by address
|
/* Return non-zero if the two addresses are equal, either by address
|
||||||
* or by hostname if they could not have been resolved.
|
* or by hostname if they could not have been resolved.
|
||||||
*/
|
*/
|
||||||
|
@ -1616,7 +1611,7 @@ int sentinelResetMasterAndChangeAddress(sentinelRedisInstance *master, char *hos
|
||||||
while((de = dictNext(di)) != NULL) {
|
while((de = dictNext(di)) != NULL) {
|
||||||
sentinelRedisInstance *slave = dictGetVal(de);
|
sentinelRedisInstance *slave = dictGetVal(de);
|
||||||
|
|
||||||
if (sentinelAddrIsEqual(slave->addr,newaddr)) continue;
|
if (sentinelAddrOrHostnameEqual(slave->addr,newaddr)) continue;
|
||||||
slaves[numslaves++] = dupSentinelAddr(slave->addr);
|
slaves[numslaves++] = dupSentinelAddr(slave->addr);
|
||||||
}
|
}
|
||||||
dictReleaseIterator(di);
|
dictReleaseIterator(di);
|
||||||
|
@ -1624,7 +1619,7 @@ int sentinelResetMasterAndChangeAddress(sentinelRedisInstance *master, char *hos
|
||||||
/* If we are switching to a different address, include the old address
|
/* If we are switching to a different address, include the old address
|
||||||
* as a slave as well, so that we'll be able to sense / reconfigure
|
* as a slave as well, so that we'll be able to sense / reconfigure
|
||||||
* the old master. */
|
* the old master. */
|
||||||
if (!sentinelAddrIsEqual(newaddr,master->addr)) {
|
if (!sentinelAddrOrHostnameEqual(newaddr,master->addr)) {
|
||||||
slaves[numslaves++] = dupSentinelAddr(master->addr);
|
slaves[numslaves++] = dupSentinelAddr(master->addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2175,7 +2170,7 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) {
|
||||||
* slave's address, a failover is in progress and the slave was
|
* slave's address, a failover is in progress and the slave was
|
||||||
* already successfully promoted. So as the address of this slave
|
* already successfully promoted. So as the address of this slave
|
||||||
* we use the old master address instead. */
|
* we use the old master address instead. */
|
||||||
if (sentinelAddrIsEqual(slave_addr,master_addr))
|
if (sentinelAddrOrHostnameEqual(slave_addr,master_addr))
|
||||||
slave_addr = master->addr;
|
slave_addr = master->addr;
|
||||||
line = sdscatprintf(sdsempty(),
|
line = sdscatprintf(sdsempty(),
|
||||||
"sentinel known-replica %s %s %d",
|
"sentinel known-replica %s %s %d",
|
||||||
|
|
Loading…
Reference in New Issue