配置一个延时复制节点¶
To configure a delayed secondary member, set its members[n].priority value to 0, its members[n].hidden value to true, and its members[n].slaveDelay value to the number of seconds to delay.
重要
The length of the secondary members[n].slaveDelay must fit within the window of the oplog. If the oplog is shorter than the members[n].slaveDelay window, the delayed member cannot successfully replicate operations.
当我们配置一个延时节点的时候,复制过程与 该节点的 oplog 都将延时。有关延时节点的更多信息请参考 延时节点 。
例子¶
The following example sets a 1-hour delay on a secondary member currently at the index 0 in the members array. To set the delay, issue the following sequence of operations in a mongo shell connected to the primary:
cfg = rs.conf()
cfg.members[0].priority = 0
cfg.members[0].hidden = true
cfg.members[0].slaveDelay = 3600
rs.reconfig(cfg)
After the replica set reconfigures, the delayed secondary member cannot become primary and is hidden from applications. The members[n].slaveDelay value delays both replication and the member’s oplog by 3600 seconds (1 hour).
When updating the replica configuration object, access the replica set members in the members array with the array index. The array index begins with 0. Do not confuse this index value with the value of the members[n]._id field in each document in the members array.
警告
- The rs.reconfig() shell method can force the current primary to step down, which causes an election. When the primary steps down, the mongod closes all client connections. While this typically takes 10-20 seconds, try to make these changes during scheduled maintenance periods.
为了能让复制集的配置修改成功应用,我们需要确保复制集的多数节点是可用的。如果我们的复制集是由偶数个节点组成的,那就需要新增一个 arbiter 来确保选举的正常进行。