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值设置为延迟的秒数。

Important重要

The length of the 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.如果oplog短于members[n].secondaryDelaySecs窗口,则延迟的成员无法成功复制操作。

When you configure a delayed member, the delay applies both to replication and to the member's oplog. 配置延迟成员时,延迟同时适用于复制和成员的oplogFor 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值将复制和成员的oplog延迟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数组中每个文档中的members[n]._id字段的值混淆。

Warning警告
  • The rs.reconfig() shell method can force the current primary to step down, which causes an election.rs.reconfig()shell方法可以强制当前的初选下台,从而导致选举 When the primary steps down, the 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版本而异。

Related Documents相关文件

←  Configure a Hidden Replica Set MemberConfigure Non-Voting Replica Set Member →