Configure a Delayed Replica Set Member配置延迟的副本集成员
On this page本页内容
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].secondaryDelaySecs
value to the number of seconds to delay.members[n].priority
值设置为0
,将其members[n].hidden
值设置为true
,将其members[n].secondaryDelaySecs
值设置为要延迟的秒数。
The length of the secondary secondary的 members[n].secondaryDelaySecs
must fit within the window of the oplog. members[n].secondaryDelaySecs
的长度必须适合oplog的窗口。If the oplog is shorter than the 如果操作日志短于members[n].secondaryDelaySecs
window, the delayed member cannot successfully replicate operations.members[n].secondaryDelaySecs
窗口,则延迟的成员无法成功复制操作。
When you configure a delayed member, the delay applies both to replication and to the member's oplog. 配置延迟成员时,延迟同时应用于复制和成员的操作日志。For details on delayed members and their uses, see Delayed Replica Set Members.有关延迟成员及其使用的详细信息,请参阅延迟副本集成员。
Example实例
The following example sets a 1-hour delay on a secondary member currently at the index 以下示例对0
in the members
array. members
数组中当前索引为0
的辅助成员设置1小时的延迟。To set the delay, issue the following sequence of operations in a 要设置延迟,请在连接到主服务器的mongosh
session that is connected to the primary:mongosh
会话中发出以下操作序列:
cfg = rs.conf()
cfg.members[0].priority = 0
cfg.members[0].hidden = true
cfg.members[0].secondaryDelaySecs = 3600
rs.reconfig(cfg)
After the replica set reconfigures, the delayed secondary member cannot become primary and is hidden from applications. 复制副本集重新配置后,延迟的辅助成员将无法成为primary,并对应用程序隐藏。The members[n].secondaryDelaySecs
value delays both replication and the member's oplog by 3600 seconds (1 hour).members[n].secondaryDelaySecs
值将复制和成员的操作日志延迟3600秒(1小时)。
When updating the replica configuration object, access the replica set members in the 更新副本配置对象时,请使用数组索引访问members
array with the array index. members
数组中的副本集成员。The array index begins with 数组索引以0
. 0
开头。Do not confuse this index value with the value of the 不要将此索引值与成员数组中每个文档中的members[n]._id
field in each document in the members
array.members[n]._id
字段的值混淆。
Thers.reconfig()
shell method can force the current primary to step down, which causes an election.rs.reconfig()
shell方法可以强制当前的primary退出,从而导致选举。When the primary steps down, the当primary关闭时,mongod
closes all client connections.mongod
会关闭所有客户端连接。While this typically takes 10-20 seconds, try to make these changes during scheduled maintenance periods.虽然这通常需要10-20秒,但请尝试在计划维护期间进行这些更改。Avoid reconfiguring replica sets that contain members of different MongoDB versions as validation rules may differ across MongoDB versions.避免重新配置包含不同MongoDB版本成员的副本集,因为验证规则可能因MongoDB版本而异。