定义
mergeChunksFor a sharded collection,
mergeChunkscombines contiguous chunk ranges on a shard into a single chunk. Issue themergeChunkscommand on theadmindatabase from amongosinstance.
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.adminCommand( { mergeChunks: <namespace>, bounds : [ { <shardKeyField>: <minFieldValue> }, { <shardKeyField>: <maxFieldValue> } ] } )
For compound shard keys, you must include the full shard key in the bounds specification. For example, if the shard key is { x: 1, y: 1 }, mergeChunks has the following form:
db.adminCommand( { mergeChunks: <namespace>, bounds: [ { x: <minValue>, y: <minValue> }, { x: <maxValue>, y: <maxValue> } ] } )
命令字段
该命令接受以下字段:
字段 | 类型 | 说明 |
|---|---|---|
| namespace | 两个数据块都 存在 的collection的完全限定 命名空间 。命名空间采用 |
| 阵列 | 包含新数据段的最小和最大键值的数组。 |
访问控制
在使用authorization运行的部署中,内置角色clusterManager提供所需的权限。
行为
注意
Use the mergeChunks only in special circumstances. For instance, when cleaning up your sharded cluster after removing many documents.
为了成功合并数据块,必须满足以下条件:
在
bounds字段中,<minkey>和<maxkey>必须对应于要合并的数据块的下限和上限。这些数据段必须驻留在同一分片上。
数据块必须是连续的。
mergeChunks 如果不满足这些条件,则会返回错误。
返回消息
On success, mergeChunks returns this document:
{ "ok" : 1, "$clusterTime" : { "clusterTime" : Timestamp(1510767081, 1), "signature" : { "hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="), "keyId" : Long("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }
另一项操作正在进行中
mergeChunks returns the following error message if another metadata operation is in progress on the chunks collection:
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. You can retry the mergeChunks operation without side effects.
不同分片上的数据块
If the input chunks are not on the same shard, mergeChunks returns an error similar to the following:
{ "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" : Long("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }
非连续数据块
If the input chunks are not contiguous, mergeChunks returns an error similar to the following:
{ "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" : Long("6488693018630029321") } }, "operationTime" : Timestamp(1510767081, 1) }