setIndexCommitQuorum
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.
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
注意
このコマンドは、すべての MongoDB Atlas クラスターでサポートされています。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
このコマンドの構文は、次のとおりです。
db.runCommand( { setIndexCommitQuorum: <string>, indexNames: [ <document> ], commitQuorum: <int> | <string>, comment: <any> } )
コマンドフィールド
このコマンドは、次のフィールドを使用します。
フィールド | タイプ | 説明 |
---|---|---|
| The name of the collection for which the indexes are being built. | |
| 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 | |
| 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 Starting in MongoDB v5.0, it's possible to resume some
interrupted index builds
when the commit quorum is set to To update the commitQuorum, member replica set nodes must have
次の値をサポートします。
| |
| any | 任意。このコマンドに添付するユーザー指定のコメント。設定すると、このコメントは以下の場所にこのコマンドの記録と合わせて表示されます。
コメントには、有効な BSON 型(string, integer, object, array など)を使用できます。 |
動作
注意
FeatureCompatibilityVersion 4.4 以上が必要です。
レプリカセット全体でインデックス構築を同時に開始するには、レプリカセットまたはシャーディングされたクラスター内の各 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.
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.
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.
Issuing setIndexCommitQuorum
has no effect on index builds
started with commitQuorum of
0
.
重要
Replica set nodes with buildIndexes
set to false
can't be included in a commit quorum.
コミットクォーラムと書込み保証の対比
インデックス構築にはコミットクォーラムを使用します。
書き込み操作には書込み保証が必要です。
クラスタ内の各データ保有ノードは投票ノードです。
コミットクォーラムは、プライマリを含むデータを保持する投票ノードの数、またはどの投票ノードがインデックス構築を同時にコミットする準備ができている必要があるかを指定し、その後プライマリがコミットを実行します。
書き込み保証 (write concern) とは、指定された数のインスタンスに書き込み (write) が伝わったことを確認するレベルです。
バージョン 8.0 での変更: コミットクォーラムでは、プライマリがインデックス構築にコミットする前に、インデックス構築を完了する準備が整っていなければならないノードの数を指定します。対照的に、プライマリがインデックス構築にコミットした時に、書き込み保証によって、コマンドが正常に返されるまでにインデックス構築の oplog エントリを複製する必要があるノードの数が指定されます。
以前のリリースでは、プライマリがインデックス構築にコミットした時に、書き込み保証によって、コマンドが正常に返されるまでにインデックス構築を完了する必要があるノードの数が指定されていました。
例
レプリカセットまたはシャーディングされたクラスター上のインデックスは、データを保持するすべてのレプリカセット ノードで同時に構築されます。シャーディングされたクラスターの場合、インデックス構築は、インデックスが作成されるコレクションのデータを含むシャードでのみ行われます。プライマリは、インデックスを使用可能とマークする前に、自身を含む最小限のデータを保持する voting
ノード(コミットクォーラム)でインデックス構築を完了する必要があります。詳細については、「レプリケートされた環境でのインデックス構築」を参照してください。
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:.
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. thecreateIndexes()
operation.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.