Commit 0101c2bc authored by antirez's avatar antirez
Browse files

Sentinel: select slave with best (greater) replication offset.

parent a6ebd910
...@@ -2903,6 +2903,9 @@ int sentinelStartFailoverIfNeeded(sentinelRedisInstance *master) { ...@@ -2903,6 +2903,9 @@ int sentinelStartFailoverIfNeeded(sentinelRedisInstance *master) {
* NULL if no suitable slave was found. * NULL if no suitable slave was found.
*/ */
/* Helper for sentinelSelectSlave(). This is used by qsort() in order to
* sort suitable slaves in a "better first" order, to take the first of
* the list. */
int compareSlavesForPromotion(const void *a, const void *b) { int compareSlavesForPromotion(const void *a, const void *b) {
sentinelRedisInstance **sa = (sentinelRedisInstance **)a, sentinelRedisInstance **sa = (sentinelRedisInstance **)a,
**sb = (sentinelRedisInstance **)b; **sb = (sentinelRedisInstance **)b;
...@@ -2911,8 +2914,16 @@ int compareSlavesForPromotion(const void *a, const void *b) { ...@@ -2911,8 +2914,16 @@ int compareSlavesForPromotion(const void *a, const void *b) {
if ((*sa)->slave_priority != (*sb)->slave_priority) if ((*sa)->slave_priority != (*sb)->slave_priority)
return (*sa)->slave_priority - (*sb)->slave_priority; return (*sa)->slave_priority - (*sb)->slave_priority;
/* If priority is the same, select the slave with that has the /* If priority is the same, select the slave with greater replication
* lexicographically smaller runid. Note that we try to handle runid * offset (processed more data frmo the master). */
if ((*sa)->slave_repl_offset > (*sb)->slave_repl_offset) {
return -1; /* a < b */
} else if ((*sa)->slave_repl_offset < (*sb)->slave_repl_offset) {
return 1; /* b > a */
}
/* If the replication offset 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 * == NULL as there are old Redis versions that don't publish runid in
* INFO. A NULL runid is considered bigger than any other runid. */ * INFO. A NULL runid is considered bigger than any other runid. */
sa_runid = (*sa)->runid; sa_runid = (*sa)->runid;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment