rs.stepDown()

On this page本页内容

Description描述

rs.stepDown(stepDownSecs, secondaryCatchUpPeriodSecs)

Instructs the primary of the replica set to become a secondary. 指示复制副本集的primary变为secondaryAfter the primary steps down, eligible secondaries will hold an election for primary.初选下台后,合格的二级候选人将举行primary选举

The method does not immediately step down the primary. 该方法不会立即停止主进程。If no electable secondaries are up to date with the primary, the primary waits up to secondaryCatchUpPeriodSecs (by default 10 seconds) for a secondary to catch up. Once an electable secondary is available, the method steps down the primary.如果没有electable辅助设备与主设备保持最新,则主设备最多等待secondaryCatchUpPeriodSecs(默认情况下为10秒),以便辅助设备赶上。一旦有了可选修的二级课程,该方法将逐步减少初级课程。

Once stepped down, the original primary becomes a secondary and is ineligible from becoming primary again for the remainder of time specified by stepDownSecs.一旦降级,原始主节点将变为次节点,并且在stepDownSecs指定的剩余时间内无法再次成为主节点。

For a detailed explanation of the method 's execution, see Behavior.有关方法执行的详细说明,请参阅行为

Note注意

The method is only valid against the primary and throws an error if run on a non-primary member.该方法仅对主成员有效,如果在非主成员上运行,则会引发错误。

The rs.stepDown() method has the following parameters:rs.stepDown()方法具有以下参数:

Parameter参数Type类型Description描述
stepDownSecsnumber

The number of seconds to step down the primary, during which time the stepdown member is ineligible for becoming primary. 退出主成员的秒数,在此期间,退出成员没有资格成为主成员。If you specify a non-numeric value, the command uses 60 seconds.如果指定非数值,则该命令将使用60秒。

The stepdown period starts from the time that the mongod receives the command. 降压周期从mongod收到命令的时间开始。The stepdown period must be greater than the secondaryCatchUpPeriodSecs.降压周期必须大于secondaryCatchUpPeriodSecs

secondaryCatchUpPeriodSecsnumber

Optional. 可选。The number of seconds that mongod will wait for an electable secondary to catch up to the primary.mongod等待一个可选举的次要候选人赶上主要候选人的秒数。

When specified, secondaryCatchUpPeriodSecs overrides the default wait time of 10 seconds.指定后,secondaryCatchUpPeriodSecs将覆盖默认等待时间10秒。

rs.stepDown() provides a wrapper around the command replSetStepDown.提供了命令replSetStepDown的包装。

Behavior行为

Concurrent Operations并发操作

The rs.stepDown() method attempts to terminate long running user operations that block the primary from stepping down, such as an index build, a write operation or a map-reduce job.rs.stepDown()方法尝试终止长时间运行的用户操作,这些操作阻止主进程逐步停止,例如索引构建、写入操作或映射缩减作业。

Availability of Eligible Secondaries合格助教的可用性

The method then initiates a catchup period where it waits up to secondaryCatchUpPeriodSeconds, by default 10 seconds, for a secondary to become up-to-date with the primary. 然后,该方法启动一个追赶周期,在该周期中,它最多等待secondaryCatchUpPeriodSeconds(默认为10秒),以使次节点与主节点保持最新。The primary only steps down if a secondary is up-to-date with the primary during the catchup period to prevent rollbacks.只有当辅助设备在追赶期间与主设备保持最新时,主设备才会停止运行,以防止回滚

If no electable secondary meets this criterion by the end of the waiting period, the primary does not step down and the method errors. 如果在等待期结束时,没有一个可选择的次级中学符合这一标准,则初级中学不会下课,方法也会出错。

Once the primary steps down successfully, that node cannot become the primary for the remainder of the stepDownSecs period, which began when the node received the method.一旦主节点成功下移,该节点就不能在stepDownSecs期间的剩余时间内成为主节点,该期间从节点接收该方法时开始。

Client Connections客户端连接

Starting in MongoDB 4.2, rs.stepDown() method no longer closes all client connections.从MongoDB 4.2开始,rs.stepDown()方法不再关闭所有客户端连接。

In MongoDB 4.0 and earlier, rs.stepDown() method closes all client connections during the step down. 在MongoDB 4.0及更早版本中,rs.stepDown()方法在逐步关闭期间关闭所有客户端连接。Because the disconnect includes the connection used to run the method, you cannot retrieve the return status of the method if the method completes successfully. 由于断开连接包括用于运行该方法的连接,因此如果该方法成功完成,则无法检索该方法的返回状态。You can only retrieve the return status of the method if it errors. 如果方法出错,则只能检索该方法的返回状态。When running the 4.0 and earlier method in a script, the script should account for this behavior.在脚本中运行4.0及更早版本的方法时,脚本应考虑此行为。

Writes During Stepdown下台期间写入

Note注意

All writes to the primary fail during the period starting when the rs.stepDown() method is received until either a new primary is elected, or if there are no electable secondaries, the original primary resumes normal operation.在接收到rs.stepDown()方法之后的一段时间内,所有对主文件的写入都会失败,直到选择了新的主文件,或者如果没有可选择的辅助文件,则原始主文件将恢复正常操作。

Writes that were in progress when rs.stepDown() is run are killed. 运行rs.stepDown()时正在进行的写入被终止。In-progress transactions also fail with "TransientTransactionError" and can be retried as a whole.进行中的事务也会因"TransientTransactionError"而失败,可以作为一个整体重试。

The time period where writes fail is at maximum:写入失败的最大时间段为:

secondaryCatchUpPeriodSecs (10s by default) + electionTimeoutMillis (10s by default).

Election Handoff选举交接

Changed in version 4.0.2.在版本4.0.2中更改

If the parameter enableElectionHandoff is true (default), when a primary steps down from rs.stepDown()(or the replSetStepDown command without the force: true), the stepped-down primary nominates an eligible secondary to call an election immediately. 如果参数enableElectionHandofftrue(默认值),则当一个主节点从rs.stepDown()(或不带force:truereplSetStepDown命令)退出时,退出的主节点指定一个合格的辅节点立即调用选举。Otherwise, secondaries can wait up to settings.electionTimeoutMillis before calling an election. 否则,辅助人员可以在调用选举之前等待settings.electionTimeoutMillisThe stepped down primary does not wait for the effects of the handoff. 逐步下降的主节点不等待切换的影响。For more information, see enableElectionHandoff.有关详细信息,请参阅enableElectionHandoff

←  rs.status()rs.syncFrom() →