summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-09-11 18:53:31 +0200
committerantirez <antirez@gmail.com>2014-09-11 19:28:09 +0200
commit9fe4429a0927520dd10345a86f153fe875c12025 (patch)
tree94111fda285ab03ec53acde468981641cc8501f2
parent6fbcb192755f5f2b97e76efa9499a37e0531a0ce (diff)
downloadredis-9fe4429a0927520dd10345a86f153fe875c12025.tar.gz
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).
-rw-r--r--src/sentinel.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/sentinel.c b/src/sentinel.c
index 4cc891c97..b50e680e5 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))