replSetStepDown

On this page本页内容

Description描述

replSetStepDown

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下台后,合格的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. 如果没有electablesecondaryprimary保持最新状态,则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.有关命令执行的详细说明,请参阅行为

Note注意

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:将以下字段作为参数:

Field字段Type类型Description描述
replSetStepDownnumber

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 the mongod will wait for an electable secondary to catch up to the primary.mongod等待可选择的辅助设备赶上主设备的秒数。

When specified, secondaryCatchUpPeriodSecs overrides the default wait time of either 10 seconds or if force: true, 0 seconds.如果指定,secondaryCatchUpPeriodSecs将覆盖默认的等待时间,即10秒,如果force:true,则为0秒。

forceboolean

Optional. 可选。A boolean that determines whether the primary steps down if no electable and up-to-date secondary exists within the wait period.一个布尔值,如果在等待期内不存在可选择且最新的辅助级,则确定主级是否降级。

If true, the primary steps down even if no suitable secondary member exists; this could lead to rollbacks if a secondary with replication lag becomes the new primary.如果为真,则即使不存在合适的次要成员,主要成员也会降级;如果具有复制滞后的辅助服务器成为新的主服务器,这可能会导致回滚

If false, the primary does not step down if no suitable secondary member exists and the command returns an error.如果为false,则如果不存在合适的辅助成员,则主成员不会退出,并且命令返回错误。

Defaults to false.默认为false

Behavior行为

Concurrent Operations并发操作

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命令尝试终止阻止主进程降级的长时间运行的用户操作,例如索引生成、写入操作或映射减少作业。

Availability of Eligible Secondaries合格辅助人员的可用性

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>时段的剩余时间内成为主节点,该时段从节点收到命令开始。

Client Connections客户端连接

Starting in MongoDB 4.2, replSetStepDown command no longer closes all client connections.从MongoDB 4.2开始,replSetStepDown命令不再关闭所有客户端连接。

In MongoDB 4.0 and earlier, replSetStepDown command closes all client connections during the step down. 在MongoDB 4.0及更早版本中,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及更早版本的命令时,脚本应考虑此行为。

Writes During Stepdown降级期间的写入

Note注意

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秒)。

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.electionTimeoutMillis后再进行选举。The stepped down primary does not wait for the effects of the handoff. 降级的主节点不等待切换的影响。For more information, see enableElectionHandoff.有关详细信息,请参阅enableElectionHandoff

Examples示例

Step Down with Default Options使用默认选项降级

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 seconds for a secondary to catch up. 该操作将等待默认的10秒,以使辅助设备赶上。If no suitable secondary exists, the primary does not step down and the command errors.如果不存在合适的辅助设备,则主设备不会降级,并且命令错误。

Note注意

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 } )

Specify Wait Time for Secondary Catch Up指定辅助追赶的等待时间

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.如果不存在合适的辅助设备,则主设备不会降级,并且命令错误。

Note注意

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 } )

Specify Secondary Catch Up with Force Step Down指定带有强制降级的辅助追赶

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选项,即使不存在合适的辅助级,主级也会降级。

Note注意

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 } )
Tip提示
See also: 参阅:
←  replSetResizeOplogreplSetSyncFrom →