对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

rs.stepDown()(mongosh方法)

rs.stepDown(stepDownSecs, secondaryCatchUpPeriodSecs)

指示副本集的主节点 (primary node in the replica set)成为从节点(secondary node from replica set)。主节点 (primary node in the replica set)节点降级后,符合条件的从节点将进行主节点 (primary node in the replica set)选举

该方法不会立即降级主节点。如果没有 electable 从节点与主节点保持同步,则主节点将等待 secondaryCatchUpPeriodSecs (默认为 10 秒)以便从节点同步。一旦有可选的从节点可用,该方法步骤就会降级主节点。

一旦降级,原来的主节点将成为从节点,并且在 stepDownSecs 指定的剩余时间内没有资格再次成为主节点。

有关该方法执行的详细说明,请参阅行为

注意

此方法仅对主节点有效,如果在非主节点上运行,则会抛出错误。

重要

mongosh 方法

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

有关数据库命令,请参阅 replSetStepDown 命令。

如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。

The rs.stepDown() method has the following parameters:

Parameter
类型
说明

stepDownSecs

数字

从主节点降级的时间(秒),在此期间,降级节点没有资格成为主节点。如果指定非数字值,该命令将使用 60 秒。

降级周期从 mongod 收到命令的时间开始。降级周期必须大于 secondaryCatchUpPeriodSecs

secondaryCatchUpPeriodSecs

数字

可选。mongod 等待可选举的辅助节点与主节点同步的秒数。

指定后,secondaryCatchUpPeriodSecs 将覆盖 10 秒的默认等待时间。

此方法可用于以下环境中托管的部署:

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.

然后,此方法然将启动一个追赶期,等待 secondaryCatchUpPeriodSeconds(默认为 10 秒),以便从节点与主节点保持同步。仅当从节点在追赶期间与主节点保持同步时,主节点才会降级,防止回滚

如果在等待期结束时没有可选的从节点满足此标准,则主节点不会降级,且该方法出错。

主节点成功降级后,该节点在 stepDownSecs 时间段的剩余时间内将无法成为主节点,该时间段从节点收到该方法时开始。

rs.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.

Writes that were in progress when rs.stepDown() is run are killed. In-progress transactions also fail with TransientTransactionError and can be retried as a whole.

写入失败的时间段最长为:

secondaryCatchUpPeriodSecs (默认为 10 秒)+ electionTimeoutMillis(默认为 10 秒)。

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.

给本页内容打分

在此页面上