setIndexCommitQuorumThesetIndexCommitQuorumcommand 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:该命令包含以下字段:
setIndexCommitQuorum | string |
|
indexNames | array |
|
commitQuorum | int or string |
|
comment |
|
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对以commitQuorum为0启动的索引构建没有影响。
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为indexNamesmust be the entire set of in-progress builds associated to a given index builder, i.e. thecreateIndexes()operation.indexNames指定的索引必须是与给定索引生成器关联的整个正在进行的构建集,即createIndexes()操作。TheindexNamesfield 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通过连接索引字段的名称和排序顺序来生成索引名称。