Database Manual / Reference / Database Commands / Replication

replSetMaintenance (database command数据库命令)

Definition定义

replSetMaintenance
The replSetMaintenance admin command enables or disables the maintenance mode for a secondary member of a replica set.replSetMaintenance管理命令启用或禁用副本集secondary成员的维护模式。

Compatibility兼容性

This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Important

This command is not supported in MongoDB Atlas clusters. MongoDB Atlas集群不支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令

Syntax语法

The command has the following syntax:该命令具有以下语法:

db.runCommand(
{
replSetMaintenance: <boolean>
}
)

Behavior行为

Consider the following behavior when running the replSetMaintenance command:运行replSetMaintenance命令时,请考虑以下行为:

  • You cannot run the command on the Primary.您无法在主服务器上运行该命令。
  • You must run the command against the admin database.您必须对admin数据库运行该命令。
  • When enabled replSetMaintenance: true, the member enters the RECOVERING state. While the secondary is RECOVERING:启用replSetMaintenance:true时,成员将进入RECOVERING状态。当secondary正在恢复时:

    • The member is not accessible for read operations.该成员无法进行读取操作。
    • The member continues to sync its oplog from the Primary.该成员继续从主服务器同步其oplog
  • When a node receives a replSetMaintenance: true request, it adds a maintenance mode task to a queue of tasks. 当节点收到replSetMaintenance: true请求时,它会将维护模式任务添加到任务队列中。If the queue of tasks was empty and now is not, the node will transition to RECOVERING state and begin to reject read requests. 如果任务队列为空,而现在不是,则节点将转换到RECOVERING状态并开始拒绝读取请求。When a node receives a replSetMaintenance: false request, it removes a maintenance mode task from the queue (even if that task was initiated by a different client). If the request empties the maintenance mode task queue, the node will return to SECONDARY state.当节点收到replSetMaintenance:false请求时,它会从队列中删除维护模式任务(即使该任务是由其他客户端发起的)。如果请求清空了维护模式任务队列,则节点将返回SECONDARY状态。
  • If you want to prevent a node from servicing reads, consider using Hidden Replica Set Members instead.如果要阻止节点为读取提供服务,请考虑使用隐藏副本集成员