-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Execution
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Problem
UpdateArrayNode keeps every merged update subtree in _mergedChildrenCache for the lifetime of the update tree. In a multi: true update the cache persists across documents. SERVER-138477 bounds the work per document and clears all caches at 1000 entries, but the clear threshold counts entries, not bytes. An entry is a deep copy of a merged tree, so its size grows with the number of array filters in the merge chain, and nothing caps that number. Memory held between documents is therefore bounded by about 1000 times the size of one entry, not by a byte limit.
Proposed fix
- Pass an OperationMemoryUsageTracker (src/mongo/db/memory_tracking/) to UpdateArrayNode::apply() through UpdateExecutor::ApplyParams. UpdateDriver::update() already receives opCtx.
- Call add(diff) when a merge is stored in the cache and when the caches are cleared. An estimate per node is enough. I measured about 107 bytes per node on a synthetic workload.
- Decide what happens at the budget. Query memory load shedding exempts writes (see SERVER-138478), so charging the tracker alone gives visibility, not an abort.
Scope
Master only. Follow-up to SERVER-138477, motivated by a Secateur finding on PR 66267 (cross-document cache growth).