Sentinel — quorum detects, majority elects

Sentinels reach ODOWN at quorum agreement but require a strict majority to elect a failover leader, and Sentinel does not stop the partitioned old master from accepting writes — that is the data plane's job.

Previously

Replicas hold a copy, but they don't decide on their own when to take over. Sentinel is the small, separate process that watches, votes, and promotes.

Scene 07

Sentinel — quorum detects, majority elects

  1. Watch
  2. Try it
  3. Predict
  4. Capture
masterMASTERaccepting writesPSYNCreplicaREPLICAS1ep 0SDOWNODOWN (q=2)vote → —S2ep 0SDOWNODOWN (q=2)vote → —S3ep 0SDOWNODOWN (q=2)vote → —
3 Sentinels · quorum 2 (ODOWN) · majority 2 (elect).
What to watch for

Three Sentinels watch one master and a replica. The master crashes; watch SDOWN turn into ODOWN once quorum agrees, then a vote in epoch 1 elects the leader who promotes the replica.

Continue unlocks when the animation finishes.
Implementation

Highlighted lines are the ones running in the diagram right now.

Sentinel.tick
periodic: detect SDOWN locally, escalate to ODOWN at quorum
def tick(self):
if not master.responds_within(down_after_ms):
self.mark_sdown() # local opinion only
# ask peers via SENTINEL is-master-down-by-addr
odown_agree_count = 1 + sum(
1 for peer in peers if peer.thinks_sdown(master)
)
if odown_agree_count >= quorum:
self.status = ODOWN # quorum-agreed
self.start_election()
Sentinel.startElection
bump epoch, broadcast a vote request, collect peer votes
def start_election(self):
if self.status != ODOWN:
return
self.my_epoch += 1 # fence this round
self.vote_for = self.id
broadcast(VoteRequest(
candidate = self.id,
epoch = self.my_epoch,
))
self.tally = collect_votes_from_peers(
epoch = self.my_epoch,
)
Sentinel.tallyVotes (majority required)
ODOWN used quorum; election uses majority — different counters
def tally_votes(self):
majority = (sentinel_count // 2) + 1 # NOT quorum
if max(self.tally.values()) >= majority:
winner = argmax(self.tally)
promote(replica) # SLAVEOF NO ONE
return
if all_voted_and_no_majority(self.tally):
self.state = TIED
retry_in(2 * failover_timeout) # bumps epoch

Where this sits in Build Redis

Scene 07 of 10, in the HA act — Replication and Sentinel — async by design.. SDOWN/ODOWN ladder, epoch-based election, and the operator footgun: quorum ≠ majority.

Up next. Cluster — Sentinel keeps one master and its replicas available. But you still only have one master's worth of write throughput. Cluster is how you get more.

All 10 scenes in Build Redis · Every curriculum

Built with Arqly
Every scene in Build Redis builds on the one before it.All 10 Build Redis scenes