Definition定义
mergeChunksFor a sharded collection,对于分片集合,mergeChunkscombines contiguous chunk ranges on a shard into a single chunk. Issue themergeChunkscommand on theadmindatabase from amongosinstance.mergeChunks将分片上的连续块范围组合成一个块。从mongos实例对管理数据库发出mergeChunks命令。
Compatibility兼容性
This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Syntax语法
The command has the following syntax:该命令具有以下语法:
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:bounds规范中包含完整的分片键。例如,如果分片键是{ x: 1, y: 1 },那么mergeChunks的形式如下:
db.adminCommand(
{
mergeChunks: <namespace>,
bounds: [
{ x: <minValue>, y: <minValue> },
{ x: <maxValue>, y: <maxValue> }
]
}
)Command Fields命令字段
The command takes the following fields:该命令包含以下字段:
mergeChunks | <database>.<collection>.<database>.<collection>的形式。 | |
bounds |
Access Control访问控制
On deployments running with 在authorization, the built-in role clusterManager provides the required privileges.authorization运行的部署中,内置的角色clusterManager提供所需的权限。
Behavior行为
Note
Use the 仅在特殊情况下使用mergeChunks only in special circumstances. For instance, when cleaning up your sharded cluster after removing many documents.mergeChunks。例如,在删除许多文档后清理分片集群时。
In order to successfully merge chunks, the following must be true:为了成功合并块,必须满足以下条件:
In the在边界字段中,boundsfield,<minkey>and<maxkey>must correspond to the lower and upper bounds of the chunks to merge.<minkey>和<maxkey>必须对应于要合并的块的下限和上限。The chunks must reside on the same shard.这些块必须位于同一个分片上。The chunks must be contiguous.这些块必须是连续的。
mergeChunks returns an error if these conditions are not satisfied.如果不满足这些条件,则返回错误。
Return Messages返回消息
On success, 成功后,mergeChunks returns this document:mergeChunks将返回以下文档:
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1510767081, 1),
"signature" : {
"hash" : BinData(0,"okKHD0QuzcpbVQg7mP2YFw6lM04="),
"keyId" : Long("6488693018630029321")
}
},
"operationTime" : Timestamp(1510767081, 1)
}
Another Operation in Progress另一项操作正在进行中
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. You can retry the mergeChunks operation without side effects.mergeChunks运行时更改元数据,您可能会看到此错误。您可以在没有副作用的情况下重试mergeChunks操作。
Chunks on Different Shards不同分片上的块状物
If the input chunks are not on the same 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" : Long("6488693018630029321")
}
},
"operationTime" : Timestamp(1510767081, 1)
}Noncontiguous Chunks非连续块
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" : Long("6488693018630029321")
}
},
"operationTime" : Timestamp(1510767081, 1)
}