On this page本页内容
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()
。
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
角色提供了适当的权限。
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) } } }
"balancerCompliant" | true ) or need to be moved (false ). true )还是需要移动(false )。 | ||||||||
"firstComplianceViolation" |
Possible values are:
|
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.有关这些字段的详细信息,请参阅响应。
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) } } }