Bound MongoDB sort memory in lifecycle current listing#2603
Bound MongoDB sort memory in lifecycle current listing#2603bert-e merged 1 commit intodevelopment/8.4from
Conversation
Hello delthas,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
|
LGTM |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
|
Review by Claude Code |
|
LGTM |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## development/8.4 #2603 +/- ##
================================================
Coverage 73.37% 73.37%
================================================
Files 222 222
Lines 18160 18162 +2
Branches 3761 3786 +25
================================================
+ Hits 13324 13326 +2
Misses 4831 4831
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ab16800 to
0fd00c1
Compare
|
LGTM |
|
LGTM |
|
is this on the right branch? |
abd7044 to
79cd9e0
Compare
|
LGTM |
|
LGTM |
Add a cursor limit to DelimiterCurrent.genMDParamsV0() based on maxScannedLifecycleListingEntries (default 10,000) so MongoDB can use a bounded top-k sort instead of sorting all matching documents. The lifecycle indexes (V2LifecycleLastModifiedPrefixed and V2LifecycleDataStoreNamePrefixed) order by value.last-modified, which forces MongoDB to perform an in-memory re-sort on _id. Without a cursor limit, the SORT stage collects all matching documents before returning any results. On large buckets this can exceed the 100MB memLimit, causing MongoDB to spill to disk — which fails when the volume is under storage pressure. Issue: ARSN-565
79cd9e0 to
617c843
Compare
|
LGTM |
Jira issue not foundThe Jira issue ARSN-565 was not found. |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
|
|
/approve |
In the queueThe changeset has received all authorizations and has been added to the The changeset will be merged in:
The following branches will NOT be impacted:
There is no action required on your side. You will be notified here once IMPORTANT Please do not attempt to modify this pull request.
If you need this pull request to be removed from the queue, please contact a The following options are set: approve |
|
I have successfully merged the changeset of this pull request
The following branches have NOT changed:
Please check the status of the associated issue ARSN-565. Goodbye delthas. |
Summary
When lifecycle v2 indexes are used for current listings, MongoDB must
re-sort results by
_idin memory because the indexes are ordered byvalue.last-modified. Without a cursor.limit(), this SORT stagecollects all matching documents before returning any — which can
exceed the 100MB
memLimitand spill to disk.On systems with low disk space (the scenario described in BB-753),
this disk spill fails, breaking lifecycle processing entirely. The
problem is not index creation failing, but index usage triggering
an unbounded sort that spills to a full disk.
Fix
Add a cursor limit based on
maxScannedLifecycleListingEntries(default 10,000) in
DelimiterCurrent.genMDParamsV0(). This flowsthrough to
MongoReadStreamwhich already supportsoptions.limiton the cursor.
With the limit, MongoDB uses a bounded top-k heap sort — keeping only
~10,000 documents in memory regardless of total matches. We use
maxScannedLifecycleListingEntriesrather thanmaxKeysbecause itcounts documents scanned (not results), which maps directly to cursor
documents regardless of bucket key format (v0 or v1).
Impact
Tested on a 100k-object bucket with
explain("executionStats"):.limit().limit(1001)Issue: ARSN-565