Impact in production of adding priority in mongodb replica set

60 views
Skip to first unread message

Mukesh Kumar

unread,
Mar 10, 2016, 7:37:54 AM3/10/16
to mongodb-user
Hi,

I want to use priority in mongo replica set for a mongod instance, so that it can be primary always(if this instance is up). But when I tested the same in staging server(3 instance of mongod, 1 primary & 2 secondary), I found that, if primary(high priority) is down then one of two secondary become primary, but when primary is up again then previous primary become secondary and just up instance become primary.

In this I want to know-
1. If all write was going to previous Primary, and once new instance up and it become primary then is it possible of data loss.
2. All connection to primary will close first then it will create new connection to newly elected primary instance, but during this time if write is happening to old primary then in between that it will close that connection and will write to new primary, how safe is this.

Please let me know in detail, or share link which explain these details.

Ankur Raina

unread,
Mar 30, 2016, 11:19:00 PM3/30/16
to mongodb-user

Hi Mukesh,

if primary(high priority) is down then one of two secondary become primary, but when primary is up again then previous primary become secondary and just up instance become primary

This is the expected behaviour in cases where a replica set member with higher priority is available. Please read Replica Set Member Priority for more details.

  1. If all write was going to previous Primary, and once new instance up and it become primary then is it possible of data loss.

From MongoDB manual: While an election is in process, the replica set has no primary and cannot accept writes and all remaining members become read-only.

Electing a new primary involves failover process and may undertake a rollback. However if the write has already reflected on a majority of replica set members, it is durable.

  1. All connection to primary will close first then it will create new connection to newly elected primary instance, but during this time if write is happening to old primary then in between that it will close that connection and will write to new primary, how safe is this.

When a higher priority secondary comes up in the replica set, the existing primary will step down if the secondary is within 10 seconds of its optime else it waits until that condition is met and then steps down. This process is explained step by step in the tutorial Force a Member to Become Primary.

Regards
Ankur

Reply all
Reply to author
Forward
0 new messages