Definition定义
mergeAllChunksOnShardmergeAllChunksOnShardfinds and merges all mergeable chunks that a shard owns for a given collection.查找并合并一个分片为给定集合拥有的所有可合并块。
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(
{
mergeAllChunksOnShard: <name of the collection>,
shard: <name of the shard>,
maxNumberOfChunksToMerge: <maximum number of chunks to merge> /* optional */
}
)Command Fields命令字段
The command takes the following fields:该命令包含以下字段:
mergeAllChunksOnShard | |||
shard | |||
maxNumberOfChunksToMerge |
Behavior行为
mergeAllChunksOnShard finds and merges all mergeable chunks for a collection on the same shard. Two or more contiguous chunks in the same collection are mergeable when they meet all of these conditions:查找并合并同一分片上集合的所有可合并块。当同一集合中的两个或多个连续块满足所有这些条件时,它们是可以合并的:
They are owned by the same shard.它们属于同一个分片。They are not jumbo chunks.它们不是jumbochunks are not mergeable because they cannot participate in migrations.jumbo块的。jumbo块不可合并,因为它们不能参与迁移。Their history can be purged safely, without breaking transactions and snapshot reads:可以安全地清除它们的历史记录,而不会中断事务和快照读取:The last migration involving the chunk happened at least as many seconds ago as the value of最后一次涉及块的迁移发生在至少与minSnapshotHistoryWindowInSeconds.minSnapshotHistoryWindowInSeconds的值一样多的秒前。The last migration involving the chunk happened at least as many seconds ago as the value of涉及块的最后一次迁移发生在至少与transactionLifetimeLimitSeconds.transactionLifetimeLimitSeconds的值一样多的秒前。
Example示例
This example assumes that history is empty for all chunks and all chunks are non-jumbo. Since both conditions are true, all contiguous intervals on the same shard are mergeable.此示例假设所有块的历史记录都是空的,并且所有块都是非巨型的。由于这两个条件都为真,因此同一分片上的所有连续区间都是可合并的。
Setup设置
These chunks belong to a collection named 这些块属于一个名为coll with shard key x. There are nine chunks in total.coll的集合,其分片键为x。总共有九块。
| Chunk ID | Min | Max | Shard |
|---|---|---|---|
| A | x: 0 | x: 10 | Shard0 |
| B | x: 10 | x: 20 | Shard0 |
| C | x: 20 | x: 30 | Shard0 |
| D | x: 30 | x: 40 | Shard0 |
| E | x: 40 | x: 50 | Shard1 |
| F | x: 50 | x: 60 | Shard1 |
| G | x: 60 | x: 70 | Shard0 |
| H | x: 70 | x: 80 | Shard0 |
| I | x: 80 | x: 90 | Shard1 |
Steps步骤
Result结果
After these commands have completed, the contiguous chunks have been merged. There are four total chunks instead of the original nine.完成这些命令后,连续的块已被合并。总共有四个块,而不是原来的九个。
| Chunk ID | Min | Max | Shard |
|---|---|---|---|
| A-B-C-D | x: 0 | x: 40 | Shard0 |
| E-F | x: 40 | x: 60 | Shard1 |
| G-H | x: 60 | x: 80 | Shard0 |
| I | x: 80 | x: 90 | Shard1 |