On this page本页内容
The mergeChunks
command allows you to combine continuous chunks on the same shard into a single chunk. This tutorial explains how to merge neighboring chunks in a sharded cluster.
Note
Examples in this procedure use a members
collection in the test
database, using the username
field as the shard key.
In the mongo
shell, identify the chunk ranges with the following operation:
In the output, the chunk ranges appear after the chunk counts for each sharded collection, as in the following example:
The chunk ranges appear after the chunk counts for each sharded collection. For example, the following are the chunk ranges for the test.members
collection:
Merge contiguous chunks on the same shard.
For example, consider the following chunk ranges on shardA
:
Note
The chunks to be merged are highlighted.
To merge the highlighted contiguous chunks, issue the mergeChunks
command against the admin
database:
On success, mergeChunks
produces the following output:
On any failure condition, mergeChunks
returns a document where the value of the ok
field is 0
.
After merging the identified chunks, confirm the new chunk, as follows:
The output of sh.status()
should resemble:
After the merge, the balancer may migrate chunks across shards to ensure a more even distribution of chunks.