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.
- 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.
- 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