The AutoMerger自动合并
On this page本页内容
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每个集合的AutoMerger设置(由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.它们不是jumbo
chunks 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
. coll
的集合,该集合具有分片键x
。There are nine chunks in total.总共有九块。
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 |