mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 18:54:58 +00:00
Sentinel: do not crash against slaves not publishing the runid.
Older versions of Redis (before 2.4.17) don't publish the runid field in INFO. This commit makes Sentinel able to handle that without crashing.
This commit is contained in:
parent
58186b9dcf
commit
6276434ad2
@ -2521,9 +2521,21 @@ void sentinelStartFailoverIfNeeded(sentinelRedisInstance *master) {
|
||||
int compareSlavesForPromotion(const void *a, const void *b) {
|
||||
sentinelRedisInstance **sa = (sentinelRedisInstance **)a,
|
||||
**sb = (sentinelRedisInstance **)b;
|
||||
char *sa_runid, *sb_runid;
|
||||
|
||||
if ((*sa)->slave_priority != (*sb)->slave_priority)
|
||||
return (*sa)->slave_priority - (*sb)->slave_priority;
|
||||
return strcasecmp((*sa)->runid,(*sb)->runid);
|
||||
|
||||
/* If priority is the same, select the slave with that has the
|
||||
* lexicographically smaller runid. Note that we try to handle runid
|
||||
* == NULL as there are old Redis versions that don't publish runid in
|
||||
* INFO. A NULL runid is considered bigger than any other runid. */
|
||||
sa_runid = (*sa)->runid;
|
||||
sb_runid = (*sb)->runid;
|
||||
if (sa_runid == NULL && sb_runid == NULL) return 0;
|
||||
else if (sa_runid == NULL) return 1; /* a > b */
|
||||
else if (sb_runid == NULL) return -1; /* a < b */
|
||||
return strcasecmp(sa_runid, sb_runid);
|
||||
}
|
||||
|
||||
sentinelRedisInstance *sentinelSelectSlave(sentinelRedisInstance *master) {
|
||||
|
Loading…
Reference in New Issue
Block a user