On this page本页内容
replSetStepDown
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
下台后,合格的secondary
将举行primary选举。
The command 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. electable
secondary
与primary
保持最新状态,则primary
最多等待secondary
secondaryCatchUpPeriodSecs
(默认情况下为10秒),以使辅助设备跟上。Once an electable secondary is available, the command 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 一旦降级,原始主节点将变为辅助节点,并且在replSetStepDown: <seconds>
.replSetStepDown: <seconds>
指定的剩余时间内,不能再次成为主节点。
For a detailed explanation of the command 's execution, see Behavior.有关命令执行的详细说明,请参阅行为。
The command is only valid against the primary and throws an error if run on a non-primary member.该命令仅对主成员有效,如果在非主成员上运行,则会引发错误。
The replSetStepDown
can only run on the admin
database and has the following prototype form:replSetStepDown
只能在admin
数据库上运行,并且具有以下原型形式:
db.adminCommand( { replSetStepDown: <seconds>, secondaryCatchUpPeriodSecs: <seconds>, force: <true|false> } )
replSetStepDown
takes the following fields as arguments:将以下字段作为参数:
replSetStepDown | number |
|
secondaryCatchUpPeriodSecs | number |
|
force | boolean |
|
The replSetStepDown
command 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.replSetStepDown
命令尝试终止阻止主进程降级的长时间运行的用户操作,例如索引生成、写入操作或映射减少作业。
The command 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与主服务器保持同步。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 command errors. 如果在等待期结束时,没有可选择的辅助设备满足此标准,则主设备不会停止工作,命令错误。You can override this behavior and issue with command with the 您可以覆盖此行为,并使用force: true
option to immediately step down the primary.force:true
选项发出命令,以立即关闭主服务器。
Once the primary steps down successfully, that node cannot become the primary for the remainder of the 一旦主节点成功降级,该节点就不能在replSetStepDown: <seconds>
period, which began when the node received the command.replSetStepDown: <seconds>
时段的剩余时间内成为主节点,该时段从节点收到命令开始。
Starting in MongoDB 4.2, 从MongoDB 4.2开始,replSetStepDown
command no longer closes all client connections.replSetStepDown
命令不再关闭所有客户端连接。
In MongoDB 4.0 and earlier, 在MongoDB 4.0及更早版本中,replSetStepDown
command closes all client connections during the step down. replSetStepDown
命令在降级期间关闭所有客户端连接。Because the disconnect includes the connection used to run the command, you cannot retrieve the return status of the command if the command completes successfully. 因为断开连接包括用于运行命令的连接,所以如果命令成功完成,则无法检索命令的返回状态。You can only retrieve the return status of the command if it errors. 只有在命令出错时,才能检索该命令的返回状态。When running the 4.0 and earlier command in a script, the script should account for this behavior.在脚本中运行4.0及更早版本的命令时,脚本应考虑此行为。
All writes to the primary fail during the period starting when the 从收到replSetStepDown
command is received until either a new primary is elected, or if there are no electable secondaries, the original primary resumes normal operation.replSetStepDown
命令开始,直到选择了新的主设备,或者如果没有可选择的辅助设备,原始主设备将恢复正常操作。
Writes that were in progress when 运行replSetStepDown
is run are killed. replSetStepDown
时正在进行的写入将被终止。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)(默认为10秒) + electionTimeoutMillis
(10s by default).(默认为10秒)。
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
。
The following example, run on the current primary, attempts to step down the member for 下面的示例在当前主服务器上运行,尝试将成员降级120
seconds.120
秒。
The operation waits up to the default 该操作将等待默认的10秒,以使辅助设备赶上。10
seconds for a secondary to catch up. If no suitable secondary exists, the primary does not step down and the command errors.如果不存在合适的辅助设备,则主设备不会降级,并且命令错误。
All writes to the primary fail during the period starting when the 从收到replSetStepDown
command is received until either a new primary is elected, or if there are no electable secondaries, the original primary resumes normal operation.replSetStepDown
命令开始,直到选择了新的主设备,或者如果没有可选择的辅助设备,原始主设备将恢复正常操作。
Writes that were in progress when 运行replSetStepDown
is run are killed. replSetStepDown
时正在进行的写入将被终止。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)(默认为10秒) + electionTimeoutMillis
(10s by default).(默认为10秒)。
db.adminCommand( { replSetStepDown: 120 } )
The following example, run on the current primary, attempts to step down the member for 以下示例在当前主节点上运行,尝试将成员降级120
seconds, waiting up to 15
seconds for an electable secondary to catch up. 120
秒,最多等待15
秒,等待可选择的次节点赶上。If no suitable secondary exists, the primary does not step down and the command errors.如果不存在合适的辅助设备,则主设备不会降级,并且命令错误。
All writes to the primary fail during the period starting when the 从收到replSetStepDown
command is received until either a new primary is elected, or if there are no electable secondaries, the original primary resumes normal operation.replSetStepDown
命令开始,直到选择了新的主设备,或者如果没有可选择的辅助设备,原始主设备将恢复正常操作。
Writes that were in progress when 运行replSetStepDown
is run are killed. replSetStepDown
时正在进行的写入将被终止。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)(默认为10秒) + electionTimeoutMillis
(10s by default).(默认为10秒)。
db.adminCommand( { replSetStepDown: 120, secondaryCatchUpPeriodSecs: 15 } )
The following example, run on the current primary, attempts to step down the member for 以下示例在当前主节点上运行,尝试将成员降级120
seconds, waiting up to 15
seconds for an electable secondary to catch up. 120
秒,最多等待15
秒,等待可选择的次节点赶上。Because of the 由于force: true
option, the primary steps down even if no suitable secondary exists.force:true
选项,即使不存在合适的辅助级,主级也会降级。
All writes to the primary fail during the period starting when the 从收到replSetStepDown
command is received until either a new primary is elected, or if there are no electable secondaries, the original primary resumes normal operation.replSetStepDown
命令开始,直到选择了新的主设备,或者如果没有可选择的辅助设备,原始主设备将恢复正常操作。
Writes that were in progress when 运行replSetStepDown
is run are killed. replSetStepDown
时正在进行的写入将被终止。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)(默认为10秒) + electionTimeoutMillis
(10s by default).(默认为10秒)。
db.adminCommand( { replSetStepDown: 120, secondaryCatchUpPeriodSecs: 15, force: true } )