Starting in MongoDB 7.0, the balancer can automatically merge chunks that meet the mergeability requirements.从MongoDB 7.0开始,平衡器可以自动合并满足可合并性要求的块。
Behavior行为
The AutoMerger runs in the background as part of balancing operations. AutoMerger在后台运行,作为平衡操作的一部分。For most use cases, the default settings perform well. For details on which settings to customize for your deployment, see AutoMerger Policy.对于大多数用例,默认设置表现良好。有关为部署自定义哪些设置的详细信息,请参阅自动合并策略。
When the AutoMerger runs, it squashes together all sequences of mergeable chunks for each shard of each collection.当AutoMerger运行时,它会将每个集合的每个分片的所有可合并块序列压缩在一起。
AutoMerger Policy自动合并政策
Unless explicitly disabled, the AutoMerger starts the first time the balancer is enabled and pauses for the next 除非明确禁用,否则AutoMerger将在第一次启用平衡器时启动,并在例程耗尽后暂停下一个autoMergerIntervalSecs after the routine drains.autoMergerIntervalSecs。
When AutoMerger is enabled, automerging happens every 启用自动合并后,自动合并每autoMergerIntervalSecs seconds.autoMergerIntervalSecs秒发生一次。
For a given collection, AutoMerger guarantees that subsequent merges are delayed at least the amount specified by 对于给定的集合,AutoMerger保证后续合并至少延迟autoMergerThrottlingMS.autoMergerThrottlingMS指定的时间。
If a balancing window is set, AutoMerger only runs during the window.如果设置了平衡窗口,AutoMerger仅在窗口期间运行。
Balancing Settings Precedence平衡设置优先级
Automerging happens as part of balancing operations. In order to decide if and when to execute automerger, the settings are taken into account in this order:自动化是平衡操作的一部分。为了决定是否以及何时执行自动合并,将按以下顺序考虑设置:
Global balancing settings全局平衡设置Per-collection balancing settings (configured by每个集合的平衡设置(由configureCollectionBalancing)configureCollectionBalancing配置)- Global
AutoMerger settings自动合并设置 Per-collection AutoMerger settings (configured by每个集合的自动合并设置(由configureCollectionBalancing)configureCollectionBalancing配置)
Details详情
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块不可合并,因为它们不能参与迁移。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 |