balancerCollectionStatus

On this page本页内容

Definition定义

balancerCollectionStatus

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

Returns a document that contains information about whether the chunks of a sharded collection are balanced (i.e. do not need to be moved) as of the time the command is run or need to be moved because of draining shards, zone violation or imbalance of chunks across shards.返回一个文档,该文档包含有关在命令运行时分片集合的块是否平衡(即不需要移动)的信息,或者由于分片耗尽、区域冲突或分片之间的块不平衡而需要移动。

You can only issue the balancerCollectionStatus against the admin database.您只能针对admin数据库发出balancerCollectionStatus

The command takes the following form:该命令采用以下形式:

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

Specify the full namespace ("<db>.<collection>") of the sharded collection.指定分片集合的完整名称空间(“<db>.<collection>”)。

mongosh provides a wrapper method sh.balancerCollectionStatus().提供了一个包装方法sh.balancerCollectionStatus()

Access Control访问控制

When running with access control, the user must have the enableSharding privilege actions on database and/or collection to run the command. 当使用访问控制运行时,用户必须对数据库和/或集合具有enableSharding权限操作才能运行该命令。That is, a user must have a role that grants the following privilege:即,用户必须具有授予以下权限角色

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

The built-in clusterManager role provides the appropriate privileges.内置的clusterManager角色提供了适当的权限。

Output Document输出文档

The following is an example of a document returned by the command:以下是命令返回的文档示例:

{
   "balancerCompliant" : false,
   "firstComplianceViolation" : "chunksImbalance",
   "ok" : 1,
   "operationTime" : Timestamp(1583192967, 16),
   "$clusterTime" : {
      "clusterTime" : Timestamp(1583192967, 16),
      "signature" : {
         "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
         "keyId" : NumberLong(0)
      }
   }
}
Field字段Description描述
"balancerCompliant"A boolean that indicates whether the chunks do not need to be moved (true) or need to be moved (false). 一个布尔值,指示块是不需要移动(true)还是需要移动(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.该字段仅在"balancerCompliant"false时可用。

Possible values are:

ValueDescription描述
"draining"

A remove shard operation is in progress and MongoDB must drain chunks off the removed shard to other shard(s).移除分片操作正在进行中,MongoDB必须将移除的分片中的分片排放到其他分片中。

Note注意

If the "firstComplianceViolation" returns "draining", there may also be pending chunk migration due to "zoneViolation".如果"firstComplianceViolation"返回"draining",则也可能存在由于"zoneViolation"而导致的未决块迁移。

"zoneViolation"

Chunks violate the defined zone ranges for a shard.块违反了为分片定义的区域范围

Note注意

If the "firstComplianceViolation" responds with "zoneViolation", there may also be pending chunk migrations due to "chunksImbalance".如果"firstComplianceViolation""zoneViolation"响应,则由于"chunksImbalance",也可能存在挂起的块迁移。

"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. 集合中块最多的分片和集合中块最少的分片之间的块数差异超过了迁移阈值

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. 除了特定于命令的返回字段之外,该命令还返回操作的ok状态字段、operationTime字段和$clusterTime字段。For details on these fields, see Response.有关这些字段的详细信息,请参阅响应

Example示例

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:要检查分片集合test.contacts的块当前是否处于平衡状态,请连接到mongos实例并发出以下命令:

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:如果不需要移动集合的块,该命令将返回类似于以下内容的输出:

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