Make primary stays primary in 2-nodes-replica set

66 views
Skip to first unread message

Austin

unread,
Mar 21, 2018, 3:05:31 AM3/21/18
to mongodb-user
Hi guys,
I have been learning mongodb for about 2 months and trying things out.
My questions is how to make sure primary stays as primary with read,write access when secondary node is down/unreachable(or any other problems).
Note: replica set only contains 2 nodes, primary and secondary.
I have found 1 solution on forums however, I am not sure if I can use it for long-term and its drawbacks.
The solution is to set vote: 0 for secondary node. 
Please suggest if you have better solution and why.
Regards,
Austin



Kevin Adistambha

unread,
Mar 26, 2018, 2:33:29 AM3/26/18
to mongodb-user

Hi Austin

My questions is how to make sure primary stays as primary with read,write access when secondary node is down/unreachable(or any other problems).

Note: replica set only contains 2 nodes, primary and secondary.

A MongoDB replica set was designed to provide high availability, and it was designed to be operated with three nodes as minimum. That is, a three-node replica set can tolerate the loss of one node, and still be operational. These failure scenarios are well understood and the official drivers are expected to continue working without needing manual interference.

If two nodes are lost (or the primary cannot communicate with the other two nodes), then the remaining node will become a secondary (if it’s currently the primary).

This is to prevent a “split-brain” situation, since you cannot know if the two nodes are actually down, or is just unreachable due to network partition.

If you’re trying to force the primary to stay primary, then you’re working against the high-availability design.

In your case, there are two possible solutions that will stay within then designed replica set high availability:

  1. Have another data-bearing secondary (strongly recommended), or
  2. Have an arbiter node

An arbiter node will carry no data and allow you to have a 3-node replica set, although actually you only have 2 data-bearing node. Having said that, it is strongly recommended to have 3 data bearing nodes instead of using an arbiter.

I would recommend you to check out the Replication manual page for more details into MongoDB’s replica set.

Please note that there are some free courses in MongoDB University that may be of interest to you.

Best regards
Kevin

Reply all
Reply to author
Forward
0 new messages