From f4be6f16f2accf22d463ea557cb346d4c464870a Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 11 Sep 2014 18:53:31 +0200 Subject: [PATCH] Sentinel: fix computation of total number of votes. The code to check the number of voters was never updated to follow the new Sentinel specification, so the number of voters was computed using only the set of Sentinels that provided a vote. This means that there is a changing majority on partitions, even if usually the issue is not triggered because of the configured quorum check (what was broken was the other implicit check that requires anyway half of the known sentinels to agree in order to start a failover). --- src/sentinel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sentinel.c b/src/sentinel.c index 4cc891c9..b50e680e 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -3240,13 +3240,14 @@ char *sentinelGetLeader(sentinelRedisInstance *master, uint64_t epoch) { redisAssert(master->flags & (SRI_O_DOWN|SRI_FAILOVER_IN_PROGRESS)); counters = dictCreate(&leaderVotesDictType,NULL); + voters = dictSize(master->sentinels)+1; /* All the other sentinels and me. */ + /* Count other sentinels votes */ di = dictGetIterator(master->sentinels); while((de = dictNext(di)) != NULL) { sentinelRedisInstance *ri = dictGetVal(de); if (ri->leader != NULL && ri->leader_epoch == sentinel.current_epoch) sentinelLeaderIncr(counters,ri->leader); - voters++; } dictReleaseIterator(di); @@ -3280,7 +3281,6 @@ char *sentinelGetLeader(sentinelRedisInstance *master, uint64_t epoch) { winner = myvote; } } - voters++; /* Anyway, count me as one of the voters. */ voters_quorum = voters/2+1; if (winner && (max_votes < voters_quorum || max_votes < master->quorum))