mergeChunks

On this page本页内容

Definition定义

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命令。

Syntax语法

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> } ] } )

Command Fields命令字段

The mergeChunks command takes the following fields:mergeChunks命令接受以下字段:

Field字段Type类型Description描述
mergeChunksnamespaceThe fully qualified namespace of the collection where both chunks exist. 两个都存在的集合的完全限定命名空间Namespaces take form of <database>.<collection>. 命名空间采用<database>.<collection>的形式。
boundsarrayAn array that contains the minimum and maximum key values of the new chunk. 包含新块的最小和最大键值的数组。

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. 仅在特殊情况下使用mergeChunksFor instance, when cleaning up your sharded cluster after removing many documents.例如,在删除许多文档后清理分片集群时。

In order to successfully merge chunks, the following must be true:为了成功合并块,必须满足以下条件:

  • In the bounds field, <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" : NumberLong("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. 如果另一个进程(如平衡器进程)在mergeChunks运行时更改元数据,则可能会看到此错误。You can retry the mergeChunks operation without side effects.您可以在没有副作用的情况下重试mergeChunks操作。

Chunks on Different Shards不同分片上的分片

If the input chunks are not on the same shard, mergeChunks returns an error similar to the following:如果输入不在同一个分片上,shard, 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)
}

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" : NumberLong("6488693018630029321")
      }
  },
  "operationTime" : Timestamp(1510767081, 1)
}
←  movePrimaryrefineCollectionShardKey →