Docs Menu

balancerCollectionStatus

balancerCollectionStatus

シャーディングされたコレクションのチャンクがバランシングされているかどうか(つまり は、シャードのドレイン、ゾーン違反、またはシャード間のチャンクの不均衡により、コマンドが実行される時点で移動する必要がない場合、または移動する必要がある場合があります。

You can only issue the balancerCollectionStatus against the admin database.

Tip

mongoshでは、このコマンドはsh.balancerCollectionStatus()ヘルパー メソッドを通じて実行することもできます。

ヘルパー メソッドはmongoshユーザーには便利ですが、データベースコマンドと同じレベルの情報は返されない可能性があります。 便宜上必要ない場合、または追加の戻りフィールドが必要な場合は、 データベースコマンドを使用します。

このコマンドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

重要

このコマンドはサーバーレスインスタンスではサポートされていません。 詳細については、「サポートされていないコマンド 」を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

このコマンドの構文は、次のとおりです。

db.adminCommand(
{
balancerCollectionStatus: "<db>.<collection>"
}
)

Specify the full namespace ("<db>.<collection>") of the sharded collection.

mongosh provides a wrapper method sh.balancerCollectionStatus().

アクセス制御を使用して実行中の場合、コマンドを実行するにはenableSharding データベースやコレクション に対する 特権アクションが必要です。つまり、ユーザーは、次の 特権 を付与する ロール を持っていなければなりません。

{ resource: { db: <database>, collection: <collection> }, actions: [ "enableSharding" ] }

組み込みの clusterManager ロールにより、適切な権限が付与されます。

以下は、 コマンドによって返されるドキュメントの例えです。

{
"chunkSize": Long("128"),
"balancerCompliant" : false,
"firstComplianceViolation" : "chunksImbalance",
"ok" : 1,
"operationTime" : Timestamp(1583192967, 16),
"$clusterTime" : {
"clusterTime" : Timestamp(1583192967, 16),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
フィールド
説明

"chunkSize"

バージョン 5.3 で追加。

An integer that indicates the chunk size in megabytes.

"balancerCompliant"

A boolean that indicates whether the chunks do not need to be moved (true) or need to be moved (false).

"firstComplianceViolation"

A string that indicates the reason chunks for this namespace need to be moved. The field is only available if "balancerCompliant" is false.

可能な値は次のとおりです。

"chunksImbalance"
The difference in the number of chunks between the shard with the most chunks for the collection and the shard with the fewest chunks for the collection exceed the migration threshold.
"defragmentingChunks"
The queried namespace is currently going through the chunk defragmentation process. Defragmentation can be triggered by the configureCollectionBalancing command.
"draining"
A remove shard operation is in progress and MongoDB must drain chunks off the removed shard to other shards.
"zoneViolation"
Chunks violate the defined zone ranges for a shard.

This field only returns information on the 最初に violation observed by MongoDB. There may be additional pending chunk migrations due to a different reason than the one reported in firstComplianceViolation.

"details"

An object containing information on the ongoing defragmentation process. This object indicates the current phase of the defragmentation and how many chunks are left to process in that phase. For example output, see 進行中のデフラグ プロセス.

This field is only returned when firstComplianceViolation is defragmentingChunks.

In addition to the command-specific return fields, the command also returns the ok status field, the operationTime field, and the $clusterTime field for the operation. For details on these fields, see 応答.

To check whether the chunks of a sharded collection test.contacts is currently in balance, connect to a mongos instance and issue the following command:

db.adminCommand( { balancerCollectionStatus: "test.contacts" } )

If the chunks for the collection do not need to be moved, the command returns an output similar to the following:

{
"chunkSize": Long("128"),
"balancerCompliant" : true,
"ok" : 1,
"operationTime" : Timestamp(1583193238, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1583193238, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}

If the queried namespace is going through chunk defragmentation, the balancerCollectionStatus command returns output similar to the following:

{
"chunkSize": Long("128"),
"balancerCompliant": false,
"firstComplianceViolation": "defragmentingChunks",
"details": {
"currentPhase": "moveAndMergeChunks",
"progress": { "remainingChunksToProcess": 1 }
}
}

注意

チャンクのデフラグは複数のフェーズで行われます。 progressフィールドは現在のフェーズにのみ関連します。

To learn more about: