setIndexCommitQuorum

On this page本页内容

New in version 4.4.在版本4.4中新增

setIndexCommitQuorum

Changes the minimum number of data-bearing members (i.e commit quorum), including the primary, that must complete an in-progress simultaneous index build before the primary marks those indexes as ready.更改数据承载成员的最小数量(即提交仲裁),包括主要成员,这些成员必须在主要成员将这些索引标记为就绪之前完成正在进行的同步索引构建

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

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

The command takes the following parameters:该命令采用以下参数:

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 voting 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标记为就绪之前报告成功的索引生成A "voting" member is any replica set member where members[n].votes is greater than 0.“投票”成员是members[n].votes大于0的任何复制集成员。

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

The "votingMembers" commit quorum cannot be used if any voting replica set node is configured with members[n].buildIndexes set to false. 如果任何投票副本集节点的members[n].buildIndexes设置为false,则无法使用"votingMembers"提交仲裁。Either configure all nodes with members[n].buildIndexes set to true or select a commit quorum that requires fewer votes.配置members[n].buildIndexes设置为true的所有节点,或选择需要更少投票的提交仲裁。

Supports the following values:

  • "votingMembers" - all data-bearing voting replica set members. (Default)所有数据承载投票复制集成员。(默认)
  • "majority" - a simple majority of data-bearing voting replica set members.简单多数数据承载投票副本集成员。
  • <int> - a specific number of data-bearing voting 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类型(字符串、整数、对象、数组等)。

New in version 4.4.在版本4.4中新增

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,才能在副本集成员之间同时启动索引构建。

MongoDB 4.4 running featureCompatibilityVersion: "4.2" builds indexes on the primary before replicating the index build to secondaries.运行featureCompatibilityVersion: "4.2"的MongoDB 4.4在将索引构建复制到辅助数据库之前在主数据库上构建索引。

Issuing setIndexCommitQuorum has no effect on index builds started with commitQuorum of 0.发出setIndexCommitQuorumcommitQuorum0的索引生成没有影响。

Examples示例

Starting with MongoDB 4.4, index builds on a replica set or sharded cluster build simultaneously across all data-bearing replica set members. 从MongoDB 4.4开始,索引在副本集上构建,或在所有数据承载副本集成员上同时构建分片集群。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. 默认情况下,索引构建使用"votingMembers"提交仲裁或所有数据承载的投票副本集成员。The following operation modifies the index build commit quorum to "majority", or a simple majority of data-bearing voting members:.以下操作将索引构建提交法定人数修改为"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. 指定给indexNames的索引必须是与给定索引生成器(即。the createIndexes() operation.createIndexes()操作。
  • The indexNames field specifies the names of the indexes. indexNames字段指定索引的名称。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.由于索引是在没有显式名称的情况下创建的,MongoDB通过连接索引字段的名称和排序顺序来生成索引名称。
←  setFeatureCompatibilityVersionsetParameter →