Failover and Elections quiz

From the “detailed answer”:
Incorrect answers:
Elections can take place anytime while the primary is available.
If a majority of nodes are unavailable, elections cannot take place.”

But if a majority of nodes are unavailable, there’s no primary, right? because it becomes secondary. So maybe “Elections can take place anytime while the primary is available.” is a correct answer?

1 Like

Majority is calculated as follows:

Ceiling(No. of nodes / 2) = Majority

For example, a 5 node replica set would have a majority of 3 nodes:

5 / 2 = Ceiling(2.5) = 3

If 3 nodes (the majority) goes down, you will be left with 1 primary and 1 secondary.

PS: I’ve linked your thread to the course. Please remember to do so next time.

1 Like

I thought that if the majority of noes is unavailable then the primary becomes a secondary.
For example, from here: https://university.mongodb.com/mercury/M103/2020_April_7/chapter/Chapter_2_Replication/lesson/5a563dd2651cccdfa655d313/answer
“The key concept to understand here is that when two nodes go down in a three-node replica set, the third node becomes a secondary regardless of whether it started as a primary.”
So if we have 5 nodes and 3 go down, wouldn’t the primary become secondary?

Yes that’s right. The primary eventually steps down to become a secondary, meaning that 2 secondaries will be left running. So when node 3 comes back online, then an election takes place.

so why " Elections can take place anytime while the primary is available." is incorrect?

Because there are two cases when an election definitely takes place:

  1. When the primary steps down
  2. When the primary becomes unavailable

There’s one other case when an election may take place but not always:

  1. When you reconfigure the replica set

In other words, there’s no need for an election to take place if the Primary is available/online/healthy.

1 Like

Hi @boby_71925,

I hope you found @007_jb’s response helpful. Additionally, please refer our documentation on Replica Set Elections for more detail.

Thanks for sharing this, I will see if we can improve the language here.

~ Shubham

1 Like

Or maybe you make that statement count as correct.

Primary is available => Majority of nodes are available
Majority of nodes are available => Elections can take place

I am with @boby_71925, 100%

Moreover, if you are saying that the statement is incorrect then you are saying there are times when the primary is available but elections cannot take place.