Database Manual / Reference / Database Commands / Administration

setIndexCommitQuorum (database command数据库命令)

setIndexCommitQuorum
The setIndexCommitQuorum command sets minimum number of data-bearing members that must be prepared to commit their local index builds before the primary node will commit the index.setIndexCommitQuorum命令设置在主节点提交索引之前,必须准备提交其本地索引构建的数据承载成员的最小数量。

Compatibility兼容性

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

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Note

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

  • 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的源代码可用、免费使用和自我管理版本

Syntax语法

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

db.runCommand(
{
setIndexCommitQuorum: <string>,
indexNames: [ <document> ],
commitQuorum: <int> | <string>,
comment: <any>
}
)

Command Fields命令字段

The command takes the following fields:该命令包含以下字段:

Field字段Type类型Description描述
setIndexCommitQuorumstring

The name of the collection for which the indexes are being built.正在为其构建索引的集合的名称。

indexNamesarray

An array of in-progress index builds to modify. Each element of the array must be the name of the index.要修改的正在构建的索引数组。数组的每个元素都必须是索引的名称。

The indexes specified to indexNames must be the entire set of in-progress builds associated to a given index builder, i.e. the indexes built by a single createIndexes or db.collection.createIndexes() operation.indexNames指定的索引必须是与给定索引生成器关联的整个正在进行的构建集,即通过单个createIndexesdb.collection.createIndexes()操作构建的索引。

commitQuorumint or string

The minimum number of data-bearing replica set members (i.e. commit quorum), including the primary, that must report a successful index build before the primary marks the indexes as ready.承载数据的副本集成员(即提交仲裁)的最小数量,包括主成员,在主成员将indexes标记为就绪之前,必须报告索引构建成功。

Starting in MongoDB v5.0, it's possible to resume some interrupted index builds when the commit quorum is set to "votingMembers".从MongoDB v5.0开始,当提交仲裁设置为"votingMembers"时,可以恢复一些中断的索引构建

To update the commitQuorum, member replica set nodes must have members[n].buildIndexes set to true. 要更新commitQuorum,成员副本集节点必须将members[n].buildIndexes设置为trueIf any voting nodes have members[n].buildIndexes set to false, you can't use the default "votingMembers" commit quorum. 如果任何投票节点的members[n].buildIndexes设置为false,则无法使用默认的"votingMembers"提交仲裁。Either configure all nodes with members[n].buildIndexes set to true, or select a different commit quorum.将所有节点的members[n].buildIndexes设置为true,或选择其他提交仲裁。

Supports the following values:支持以下值:

  • "votingMembers" - all data-bearing voting replica set members (Default). A "voting" member is any replica set member where members[n].votes is greater than 0.所有承载投票副本集成员的数据(默认)。“投票”成员是指members[n].votes大于0的任何副本集成员。
  • "majority" - a simple majority of data-bearing replica set members.简单的大多数数据承载副本集成员。
  • <int> - a specific number of data-bearing replica set members. Specify an integer greater than 0.特定数量的数据承载副本集成员。指定一个大于0的整数。
  • A replica set tag name.副本集标记名
commentany任意

Optional. 可选。A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:用户提供了要附加到此命令的注释。设置后,此注释将与此命令的记录一起出现在以下位置:

A comment can be any valid BSON type (string, integer, object, array, etc).注释可以是任何有效的BSON类型(字符串、整数、对象、数组等)。

Behavior行为

Note

Requires 需要featureCompatibilityVersion 4.4+

Each mongod in the replica set or sharded cluster must have featureCompatibilityVersion set to at least 4.4 to start index builds simultaneously across replica set members.副本集或分片集群中的每个mongod都必须将featureCompatibilityVersion设置为至少4.4,才能在副本集成员之间同时启动索引构建。

Index creation is a multistage process. The index creation process uses the commit quorum to minimize replication lag on secondary nodes.索引创建是一个多阶段的过程。索引创建过程使用commit quorum(提交仲裁)来最小化辅助节点上的复制延迟。

When a secondary node receives a commitIndexBuild oplog entry, the node stops further oplog applications until the local index build can be committed. Index builds can take anywhere from moments to days to complete, so the replication lag can be significant if the secondary node builds more slowly than the primary.当辅助节点收到commitIndexBuild oplog条目时,该节点会停止进一步的oplog应用程序,直到可以提交本地索引构建。索引构建可能需要几分钟到几天的时间才能完成,因此如果辅助节点的构建速度比主节点慢,复制延迟可能会很大。

To manage the replication lag, the commit quorum delays committing the index build on the primary node until a minimum number of secondaries are also ready to commit the index build.为了管理复制延迟,提交仲裁会延迟在主节点上提交索引构建,直到最小数量的辅助节点也准备好提交索引构建。

The commit quorum does not guarantee that indexes on secondaries are ready for use when the command completes. To ensure that a specific number of secondaries are ready for use, set an appropriate write concern.提交仲裁不保证在命令完成时辅助服务器上的索引已准备好使用。为确保有特定数量的中学可供使用,请设置适当的写入关注

If a secondary node that is not included in the commit quorum receives a commitIndexBuild oplog entry, the node may block replication until its index build is complete.如果未包含在提交仲裁中的辅助节点收到commitIndexBuild oplog条目,则该节点可能会阻止复制,直到其索引构建完成。

Issuing setIndexCommitQuorum has no effect on index builds started with commitQuorum of 0.发出setIndexCommitQuorum对以commitQuorum0启动的索引构建没有影响。

Important

Replica set nodes with buildIndexes set to false can't be included in a commit quorum.buildIndexes设置为false的副本集节点不能包含在提交仲裁中。

Commit Quorum Contrasted with Write Concern提交法定人数与写入关注度的对比

There are important differences between commit quorums and write concerns:提交法定人数写入关注之间存在重要区别:

  • Index builds use commit quorums.索引构建使用提交法定人数。
  • Write operations use write concerns.写操作使用写关注。

Each data-bearing node in a cluster is a voting member.集群中的每个数据承载节点都是一个投票成员。

The commit quorum specifies how many data-bearing voting members, or which voting members, including the primary, must be prepared to commit a simultaneous index build before the primary will execute the commit.提交法定人数指定了在主要成员执行提交之前,必须准备提交多少数据承载投票成员,或哪些投票成员(包括主要成员)来提交同时的索引构建

The write concern is the level of acknowledgment that the write has propagated to the specified number of instances.写入关注是指写入已传播到指定数量的实例的确认级别。

Changed in version 8.0.在版本8.0中的更改。 The commit quorum specifies how many nodes must be ready to finish the index build before the primary commits the index build. In contrast, when the primary has committed the index build, the write concern specifies how many nodes must replicate the index build oplog entry before the command returns success.提交仲裁指定了在主提交索引构建之前,必须有多少节点准备好完成索引构建。相比之下,当主节点提交了索引构建时,写关注指定了在命令返回成功之前必须复制索引构建oplog条目的节点数量。

In previous releases, when the primary committed the index build, the write concern specified how many nodes must finish the index build before the command returned success.在以前的版本中,当主提交索引构建时,写关注指定了在命令返回成功之前必须完成多少节点的索引构建。

Examples示例

Index builds on a replica set or sharded cluster build simultaneously across all data-bearing replica set members. For sharded clusters, the index build occurs only on shards containing data for the collection being indexed. 索引基于副本集构建,或在所有承载数据的副本集成员之间同时构建分片集群。对于分片集群,索引构建仅发生在包含被索引集合的数据的分片上。The primary requires a minimum number of data-bearing voting members (i.e commit quorum), including itself, that must complete the build before marking the index as ready for use. 初选需要最少数量的数据承载voting成员(即提交法定人数),包括其本身,在将索引标记为可供使用之前,必须完成构建。See Index Builds in Replicated Environments for more information.有关更多信息,请参阅复制环境中的索引构建

The following operation starts an index build of two indexes:以下操作启动两个索引的索引构建:

db.getSiblingDB("examples").invoices.createIndexes(
[
{ "invoices" : 1 },
{ "fulfillmentStatus" : 1 }
]
)

By default, index builds use "votingMembers" commit quorum, or all data-bearing voting replica set members. The following operation modifies the index build commit quorum to "majority", or a simple majority of data-bearing voting members:.默认情况下,索引构建使用"votingMembers"提交仲裁,或所有承载数据的投票副本集成员。以下操作将索引构建提交法定人数修改为"majority",或简单多数数据承载投票成员:。

db.getSiblingDB("examples").runCommand(
{
"setIndexCommitQuorum" : "invoices",
"indexNames" : ["invoices_1", "fullfillmentStatus_1"],
"commitQuorum" : "majority"
}
)
  • The indexes specified to indexNames must be the entire set of in-progress builds associated to a given index builder, i.e. the createIndexes() operation.indexNames指定的索引必须是与给定索引生成器关联的整个正在进行的构建集,即createIndexes()操作。
  • The indexNames field specifies the names of the indexes. Since the indexes were created without an explicit name, MongoDB generated an index name by concatenating the names of the indexed fields and the sort order.indexNames字段指定索引的名称。由于索引是在没有显式名称的情况下创建的,MongoDB通过连接索引字段的名称和排序顺序来生成索引名称。