MongoDB Replica Set & Data Sync behavior

mongodbmongodb-3.4

I have a replica set with 3 nodes X, Y & A (where A is an arbiter). Currently X is assigned a higher priority than Y. When X goes down, Y becomes the PRIMARY. When X is back in action, the data sync happens, Y continues to be the PRIMARY and X acts as SECONDARY.

My requirement is as follows:

When X is back in action, I want X to automatically become the PRIMARY (i.e. without any manual intervention), once the X has synced all the data from Y.

I understand that I shouldn't be really worried about which node is primary and which one is secondary, but in my case the performance of Y node is really bad (due to the network latency) and would like to keep X as PRIMARY as much as possible.

Is there any settings / configuration in MongoDB that I can use to achieve this behavior? The version I'm using currently is 3.4.3

Thanks.

Best Answer

If you have modified X nodes priority at rs.conf() higher number than Y node, switch over should automatically happen WHEN X has replicated all information from Y node. Not before that. If switch doesn't happen, check rs.printSlaveReplicationInfo() that your X is really 0 second behind. It sounds like that your Y is so slow that even X cannot read opLog fast enough and keeps lagging that why.

Related Question