Bound MongoDB sort memory in lifecycle current listing#2603
Bound MongoDB sort memory in lifecycle current listing#2603delthas wants to merge 1 commit intodevelopment/8.3from
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.3 #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 |
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