定义
balancerCollectionStatus返回一个文档,其中包含有关分片collection的数据块是否平衡的信息(即 不需要移动),或者由于排干、区域违规或数据块不平衡而需要移动。
You can only issue the
balancerCollectionStatusagainst theadmindatabase.提示
In
mongosh, this command can also be run through thesh.balancerCollectionStatus()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.adminCommand( { balancerCollectionStatus: "<db>.<collection>" } )
指定分片collection的完整命名空间 ( "<db>.<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" : Long(0) } } }
字段 | 说明 |
|---|---|
| 5.3版本新增。 一个整数,表示数据块大小(以 MB 为单位)。 |
| 一个布尔值,表示数据块是不需要移动 ( |
| 一个字符串,表示需要移动此命名空间的数据块的原因。该字段仅当 可能的值为:
此字段仅返回 MongoDB 观察到的第一次违规的信息。 由于与 |
| 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 Ongoing Defragmentation Process. 仅当 |
除了特定于命令的返回字段之外,该命令还返回操作的ok状态字段、 operationTime字段和$clusterTime字段。 有关这些字段的详细信息,请参阅响应。
示例
要检查分片集合test.contacts的数据段当前是否均衡,请连接到mongos实例并发出以下命令:
db.adminCommand( { balancerCollectionStatus: "test.contacts" } )
如果不需要移动集合的数据段,该命令将返回类似于以下内容的输出:
{ "chunkSize": Long("128"), "balancerCompliant" : true, "ok" : 1, "operationTime" : Timestamp(1583193238, 1), "$clusterTime" : { "clusterTime" : Timestamp(1583193238, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : Long(0) } } }
正在进行的碎片整理过程
如果查询的命名空间正在进行数据块碎片整理,则balancerCollectionStatus命令将返回类似于以下内容的输出:
{ "chunkSize": Long("128"), "balancerCompliant": false, "firstComplianceViolation": "defragmentingChunks", "details": { "currentPhase": "moveAndMergeChunks", "progress": { "remainingChunksToProcess": 1 } } }
注意
数据块碎片整理分多个阶段进行。progress字段仅与当前阶段相关。
要详细了解关于:
监控碎片整理,请参阅监控分片collection的碎片整理。
对分片集合进行碎片整理,请参阅对分片集合进行碎片整理。