make replica set member passive without disconnecting clients?
Is there a way to make a secondary member of a replica set passive without stepping down the replica set which temporarily disconnects all clients? The reason why I ask is that we do backups from a secondary replica set member and so while the backup is being run I do not want it to be possible for this member to become the primary therefore I have a script which changes the priority of this member to be zero and we call rs.reconfig(). Unfortunately this causes a temporary interruption until the clients reconnect. Once the backup is complete I change the member's priority and call rs.reconfig() again. Is there another way of doing this without causing any interruptions?
Thanks, Richard.
Instead of reconfiguring the replica set, you can run rs.freeze(...)
on the secondary you are running the backup on. A frozen secondary will be ineligible to become primary during the specified period.
Once the backup is complete, you can then run rs.freeze(0)
on the secondary to unfreeze it.
Caveats to consider:
You should ensure there are sufficient data-bearing nodes in the replica set to ensure failover is still possible while the backup is running. For example, it would be risky to freeze a secondary if you have a three node replica set with primary/secondary/arbiter unless you really prefer to have an outage rather than failover (and an interrupted backup).
You should provide a number of seconds to rs.freeze()
which is reasonably longer than the expected backup period (but not excessively so) so the secondary doesn't accidentally end up frozen for an extended period if the backup process doesn't complete properly or unfreeze the secondary.
Depending on your current backup strategy, this may be unnecessary. For example, if you are using filesystem snapshots the process should complete very quickly.
上一篇: 在mongodb 3.0复制中,当一个次要级别出现时,选举是如何发生的
下一篇: 让副本集成员被动无需断开客户端?