Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB two member replica-set

I have a two member replica set (within a sharded cluster), with no arbiter. I know that the recommended design is to have three servers (or an odd number) but right now I have to stick with this design.

The problem is that when the primary is down, the secondary doesn't get elected as a temporary master (since the priority for both servers is 1 and I have no arbiter).

Is there any way to get that automatic failover (slave becomes primary -> primary back online -> default primary gets its previous state)?

Thank you!

like image 227
MariusP Avatar asked Oct 07 '13 08:10

MariusP


People also ask

What is the maximum number of nodes in MongoDB replica set?

MongoDB supports replica sets, which can have up to 50 nodes.

How does replica set work in MongoDB?

MongoDB achieves replication by the use of replica set. A replica set is a group of mongod instances that host the same data set. In a replica, one node is primary node that receives all write operations. All other instances, such as secondaries, apply operations from the primary so that they have the same data set.


1 Answers

You MUST have at least 3 members in the replicaset, having 2 members is worse than having just a single node (NEVER EVER DO THIS!!). Your problem is worst than you think, the main problem is that if your secondary goes down, your primary will demote itself to a secondary and also effectively go down because you have no more primary. I don't know why you 'have to stick with this configuration, but it can not be a solution.

The solution to this is to create an arbiter, node, this is simply a lightweight member of the replicaset that has no actual data and is simply there to take part in the election for a new primary if one of the other members goes down.

like image 134
Clinton Bosch Avatar answered Sep 19 '22 16:09

Clinton Bosch