]> git.saurik.com Git - redis.git/commitdiff
Sentinel: don't start a failover as leader if there is no good slave.
authorantirez <antirez@gmail.com>
Thu, 26 Jul 2012 10:09:40 +0000 (12:09 +0200)
committerantirez <antirez@gmail.com>
Thu, 27 Sep 2012 11:04:48 +0000 (13:04 +0200)
src/sentinel.c

index 227fb69386d1e61a6b221d8d40d187abfa32d714..24bf993f866e7108c7d8767ce2a17ccddc51d7b8 100644 (file)
@@ -294,6 +294,7 @@ void sentinelKillLink(sentinelRedisInstance *ri, redisAsyncContext *c);
 const char *sentinelRedisInstanceTypeStr(sentinelRedisInstance *ri);
 void sentinelAbortFailover(sentinelRedisInstance *ri);
 void sentinelEvent(int level, char *type, sentinelRedisInstance *ri, const char *fmt, ...);
+sentinelRedisInstance *sentinelSelectSlave(sentinelRedisInstance *master);
 
 /* ========================= Dictionary types =============================== */
 
@@ -2061,7 +2062,11 @@ void sentinelStartFailover(sentinelRedisInstance *master) {
                 SRI_RECONF_SENT);
         }
     } else {
-        /* Brand new failover as SRI_FAILOVER_IN_PROGRESS was not set. */
+        /* Brand new failover as SRI_FAILOVER_IN_PROGRESS was not set.
+         *
+         * Do we have a slave to promote? Otherwise don't start a failover
+         * at all. */
+        if (sentinelSelectSlave(master) == NULL) return;
         master->failover_state = SENTINEL_FAILOVER_STATE_WAIT_START;
     }