3

I am confused as to how MongoDB voting happens internally. The MongoDB docs don't seem to give details--they merely discuss voting at a high level. This post (Voting in MongoDB) explains the results but not the internals.

From what I have researched, two options seem possible:

  1. One member announces it is running for election. All voting members vote yes/no, and the member must receive a majority of yes's in order to be elected primary.
  2. Somehow an election is called for. All voting members place their vote for one member. Whoever receives a majority of the votes (if anyone does) then becomes primary.

I know these are similar, but I need to be able to explain how voting works for a presentation. Which option is correct? A combination?

Important followup question: What happens in a tie, or if no member receives a majority?

Community
  • 1
  • 1
thatWiseGuy
  • 384
  • 2
  • 3
  • 18

1 Answers1

3

The underpinning concept of replica set design is based on the fact that there is a majority of the replica set available when there is an election i.e odd number of members (see mongodb replica set architecture docs). In reality, this is actually a majority of the number of total votes in the replica set, which doesn't necessarily mean that there is one vote per member pre v3.0 (mongod).

Here's the way an ideal election steps out:

  1. the election is triggered
  2. the triggering member will ask other members if they will vote for it: (yes, no, veto)
  3. "yes" from majority and it will move to primary
  4. "veto" from any member an the election will fail
  5. All things remaining equal, the members vote for the member that has the highest priority
  6. If the highest priority member doesn't have the latest optime, then election process will get vetoed
  7. In a tie, the default will be the order that they're listed in the replica set config
  8. Members have to wait 30 seconds between yes votes (decrease likelihood of multiple primaries)

Sorry for lack of links, I can't post more than one

FYI, I believe v3.2 will be implementing some (if not all) of the RAFT algorithm for consensus

good explanation of elections from k chodorow: http://www.kchodorow.com/blog/2012/01/04/replica-set-internals-bootcamp-part-i-elections/

jtobs
  • 131
  • 1