Manual failover for two-node Replica Set

Hello,

I have a two node P/S replica set with the following configuration. I have a constrained environment and I’m unable to deploy a third node - arbiter or secondary. I understand that manual failover is the only option for a two-node replica set. I also understand that this is not a recommended deployment model.

The following configuration has node ‘mongodb1’ backing up to ‘mongodb2’. In the event that ‘mongodb1’ fails, I’d like to manually force ‘mongodb2’ to become the active primary.

rs.conf(): {
   _id : "rs0",
   members: [
    { _id: 0, host: 'mongodb1:27017', priority: 1, votes: 1},
    { _id: 1, host: 'mongodb2:27017', priority: 0, votes: 0 }
   ]
}

I have a couple of questions regarding this configuration.

Q1) Is this a “safe” configuration in the sense that the replica set will properly backup data from primary to secondary with ‘mongodb2’ backing up ‘mongodb1’?

Q2) Is the following command mongosh sequence a “safe” method initiating a manual failover to force ‘mongodb2’ to become primary? In particular, I’m wondering there are side effects to using {force: true} to update the replica set configuration on a secondary node?

cfg = rs.conf()
cfg.members[0].priority = 0
cfg.members[0].votes = 0
cfg.members[1].votes = 1
cfg.members[1].priority = 1
rs.reconfig(cfg, {force:true})

By “safe” I mean 1) no data corruption on primary/secondary and 2) no writes are lost while a primary node is ‘active’. (Clients will have to retry writes if there are no active primary nodes.)

Best Regards,
Matt

i think this is mostly ok, if connection between the nodes is fast enough. otherwise some of the writes may not happen yet on node2, and the clients can see a rollback after manual failover.

i recall mongodb manual explains those concepts. I’m not able to give more information than what the doc says (i’m not a mongodb employee).

Note that while 1 node is down, no writes will be able to be performed since you will not have a majority which is needed for a PRIMARY.

Is there a preferred/recommended configuration for a 2-node ReplicaSet and a preferred/recommended sequence to perform a manual failover from ‘Primary’ to ‘Secondary’?

no there is none, the recommendation is an odd number of members. with 2 you are already outside the recommendation.

2 Likes