On this page本页内容
mergeChunks
For a sharded collection, 对于分片集合,mergeChunks
combines contiguous chunk ranges on a shard into a single chunk. mergeChunks
将分片上的连续块范围合并为单个块。Issue the 从mergeChunks
command on the admin
database from a mongos
instance.mongos
实例对admin
数据库发出mergeChunks
命令。
mergeChunks
has the following form:具有以下形式:
db.adminCommand( { mergeChunks : <namespace> ,
bounds : [ { <shardKeyField>: <minFieldValue> },
{ <shardKeyField>: <maxFieldValue> } ] } )
For compound shard keys, you must include the full shard key in the 对于复合分片键,必须在bounds
specification. bounds
规范中包含完整分片键。For example, if the shard key is 例如,如果分片键是{ x: 1, y: 1 }
, mergeChunks
has the following form:{ x: 1, y: 1 }
,mergeChunks
的形式如下:
db.adminCommand( { mergeChunks : <namespace> , bounds : [ { x: <minValue>, y: <minValue> }, { x: <maxValue>, y: <maxValue> } ] } )
The mergeChunks
command takes the following fields:mergeChunks
命令接受以下字段:
mergeChunks | namespace | <database>.<collection> . <database>.<collection> 的形式。 |
bounds | array |
On deployments running with 在authorization
, the built-in role clusterManager
provides the required privileges.authorization
运行的部署中,内置角色clusterManager
提供所需的权限。
Use the 仅在特殊情况下使用mergeChunks
only in special circumstances. mergeChunks
。For instance, when cleaning up your sharded cluster after removing many documents.例如,在删除许多文档后清理分片集群时。
In order to successfully merge chunks, the following must be true:为了成功合并块,必须满足以下条件:
bounds
field, <minkey>
and <maxkey>
must correspond to the lower and upper bounds of the chunks to merge.<minkey>
和<maxkey>
必须对应于要合并的块的下限和上限。mergeChunks
returns an error if these conditions are not satisfied.如果不满足这些条件,则返回错误。
On success, 成功后,mergeChunks
returns this document:mergeChunks
返回以下文档:
{ "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1510767081, 1), "signature" : { "hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="), "keyId" : NumberLong("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }
mergeChunks
returns the following error message if another metadata operation is in progress on the 如果chunks
collection:chunks
集合上正在进行其他元数据操作,则返回以下错误消息:
errmsg: "The collection's metadata lock is already taken."
If another process, such as balancer process, changes metadata while 如果另一个进程(如平衡器进程)在mergeChunks
is running, you may see this error. mergeChunks
运行时更改元数据,则可能会看到此错误。You can retry the 您可以在没有副作用的情况下重试mergeChunks
operation without side effects.mergeChunks
操作。
If the input chunks are not on the same shard, 如果输入块不在同一个分片上,shard, mergeChunks
returns an error similar to the following:mergeChunks
会返回类似以下的错误:
{ "ok" : 0, "errmsg" : "could not merge chunks, collection test.users does not contain a chunk ending at { username: \"user63169\" }", "$clusterTime" : { "clusterTime" : Timestamp(1510767081, 1), "signature" : { "hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="), "keyId" : NumberLong("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }
If the input chunks are not contiguous, 如果输入块不连续,mergeChunks
returns an error similar to the following:mergeChunks
将返回类似于以下内容的错误:
{ "ok" : 0, "errmsg" : "could not merge chunks, collection test.users has more than 2 chunks between [{ username: \"user29937\" }, { username: \"user49877\" })" "$clusterTime" : { "clusterTime" : Timestamp(1510767081, 1), "signature" : { "hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="), "keyId" : NumberLong("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }