On this page本页内容
rs.stepDown(stepDownSecs, secondaryCatchUpPeriodSecs)
Instructs the primary of the replica set to become a secondary. 指示复制副本集的primary
变为secondary
。After 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.有关方法执行的详细说明,请参阅行为。
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()
方法具有以下参数:
stepDownSecs | number |
|
secondaryCatchUpPeriodSecs | number |
|
rs.stepDown()
provides a wrapper around the command 提供了命令replSetStepDown
.replSetStepDown
的包装。
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()
方法尝试终止长时间运行的用户操作,这些操作阻止主进程逐步停止,例如索引构建、写入操作或映射缩减作业。
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
期间的剩余时间内成为主节点,该期间从节点接收该方法时开始。
Starting in MongoDB 4.2, 从MongoDB 4.2开始,rs.stepDown()
method no longer closes all client connections.rs.stepDown()
方法不再关闭所有客户端连接。
In MongoDB 4.0 and earlier, 在MongoDB 4.0及更早版本中,rs.stepDown()
method closes all client connections during the step down. 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及更早版本的方法时,脚本应考虑此行为。
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).
Changed in version 4.0.2.在版本4.0.2中更改。
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. enableElectionHandoff
为true
(默认值),则当一个主节点从rs.stepDown()
(或不带force:true
的replSetStepDown
命令)退出时,退出的主节点指定一个合格的辅节点立即调用选举。settings.electionTimeoutMillis
before calling an election. settings.electionTimeoutMillis
。enableElectionHandoff
.enableElectionHandoff
。