liveBook · Manning

Protocol version 1

As explained in MongoDB 8.0 in Action, Third Edition

PV1 is MongoDB's replica-set election protocol version based on the Raft consensus algorithm.

Protocol version 1 (PV1) is MongoDB’s replica-set election protocol, based on the Raft consensus algorithm. It uses member voting to select a primary while supporting data consistency during failover. section 9.1.2

PV1 coordinates elections through several operational mechanisms:

  • Triggers elections when a replica set is initialized, a member is added or removed, or the primary misses heartbeats beyond the preset timeout, normally 10 seconds. section 9.1.2
  • Favors the replica with the most up-to-date write timestamp, reducing the chance of rollback when a former primary rejoins. section 9.1.2
  • Tracks election attempts with a monotonically increasing term, preventing double voting and helping detect simultaneous or repeated elections. section 9.1.2
  • Applies a freeze period after elections to limit successive elections and improve cluster stability. section 9.1.2
  • Blocks writes during an election, while reads may continue through secondary members when read routing is configured accordingly. section 9.1.2

Primary failure and recovery

If the primary becomes unavailable, secondary members vote for a replacement. With standard settings, the process normally finishes within 12 seconds; administrators can adjust electionTimeoutMillis in the replication configuration. section 9.1.2

Figure 9.1 The election mechanism within a MongoDB replica set is activated when the primary node becomes nonoperational. The secondary replicas vote to elect a new primary. (Image © MongoDB 2024 CC BY-NC-SA 3.0)

Trace the voting process that begins when a primary becomes nonoperational and secondary replicas elect a replacement. section 9.1.2

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains voting, write timestamps, terms, freeze periods, election impact, and timeout configuration without detailing implementation internals.
Examples
Uses primary unavailability, heartbeat failure, replica-set initialization, and member addition or removal as election scenarios.
What you can do after
Operate/configure replica-set failover expectations and adjust electionTimeoutMillis when deployment timing requires it.
How it connects
Connects replica sets, Raft consensus, primary and secondary members, voting, terms, heartbeats, and election timeouts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.