rs.stepDown()
On this page本页内容
Description描述
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该方法不会立即降级primary。如果没有electable
secondaries are up to date with the primary, the primary waits up tosecondaryCatchUpPeriodSecs
(by default 10 seconds) for a secondary to catch up.electable
的辅助设备是主设备的最新版本,则primary最多等待secondaryCatchUpPeriodSecs
(默认情况下为10秒),以便secondary赶上。Once an electable secondary is available, the method steps down the primary.一旦有了可选举的次级,该方法就会逐步淘汰初级。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.有关该方法执行的详细说明,请参阅行为。NoteThe method is only valid against the primary and throws an error if run on a non-primary member.该方法仅对主成员有效,如果在非主成员上运行,则会引发错误。Importantmongosh Method
This page documents a
mongosh
method. This is not the documentation for database commands or language-specific drivers, such as Node.js.For the database command, see the
replSetStepDown
command.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
For the legacy
mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:Thers.stepDown()
method has the following parameters:rs.stepDown()
方法具有以下参数:Parameter参数Type类型Description描述stepDownSecs
number 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. The stepdown period must be greater than thesecondaryCatchUpPeriodSecs
.mongod
接收到命令的时间开始。递减周期必须大于secondaryCatchUpPeriodSecs
。secondaryCatchUpPeriodSecs
number Optional.可选的。The number of seconds thatmongod
will wait for an electable secondary to catch up to the primary.mongod
将等待可选举的辅助设备赶上主设备的秒数。
When specified,如果指定,secondaryCatchUpPeriodSecs
overrides the default wait time of10
seconds.secondaryCatchUpPeriodSecs
将覆盖默认的10
秒等待时间。
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秒),以使secondary与primary同步。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, 从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. 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. rs.stepDown()
方法在关闭过程中关闭所有客户端连接。由于断开连接包括用于运行该方法的连接,因此如果该方法成功完成,则无法检索该方法的返回状态。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降级期间的写入
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 wholeTransientTransactionError
而失败,并且可以作为一个整体重试.
The time period where writes fail is at maximum:写入失败的时间段最多为:
secondaryCatchUpPeriodSecs
(10s by default)(默认为10s) +
electionTimeoutMillis
(10s by default).(默认为10s)。
Election Handoff选举交接
When you step down a primary using 当您使用rs.stepDown()
or replSetStepDown
without setting the force
field to true
, the stepped-down primary nominates an eligible secondary to call an election immediately.rs.stepDown()
或replSetStepDown
在未将force
字段设置为true
的情况下退出primary时,退出的primary会提名一个合格的secondary立即进行选举。