Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #20379 +/- ##
=============================================
+ Coverage 61.16% 71.46% +10.30%
- Complexity 1 1639 +1638
=============================================
Files 2789 3611 +822
Lines 180164 244203 +64039
Branches 30156 39699 +9543
=============================================
+ Hits 110198 174528 +64330
+ Misses 60646 56512 -4134
- Partials 9320 13163 +3843
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Idle servers can keep the leaf-stage operators of finished multi-stage queries in heap. In one heap dump taken after a full GC, 12.2 GB was live, and about 11 GB of it was the per-segment operator trees of the last 3 queries. Every segment had its own
AggregationOperator,ProjectionOperator, filter operators, transform functions andDataFetcher, with their buffers. The next queries then went over the heap limits of the resource accountant and were killed.Root cause
The heap dump shows this reference chain from the GC root:
MailboxService._receivingMailboxCacheholds aReceivingMailbox._receiveOperatorThreadContext, theQueryThreadContextof the receive operator.QueryExecutionContext. All the stages of the query on the server share it.QueryExecutionContext._tasksholds everyFuturethat the query submitted throughQueryThreadContext.contextAwareExecutorService(). Onlyterminate()clears it. A doneFutureTaskkeeps its result.CombinePlanNodebuilds the per-segment operators in parallel withQueryMultiThreadingUtils.runTasksWithDeadline(). Each task returns aList<Operator>. So_taskskeeps every per-segment operator of the leaf stage.Why the mailboxes stayed in the cache:
Fix
QueryExecutionContextkeeps only the tasks that are not done. A task submitted throughcontextAwareExecutorService()removes itself when it is done. The op chain task ofOpChainSchedulerServicedoes the same.QueryThreadContext. If the sender of the mailbox has finished, the operator also releases the mailbox from the cache. A mailbox whose sender still runs stays in the cache, as before (see Stop a lingering receiving mailbox from pinning the receive operator #19465), but it no longer keeps the query.No new configs or metrics.
Notes:
contextAwareExecutorService().submit()now builds theFutureTaskitself and gives it toexecute()of the wrapped executor. A task that is submitted after the query is terminated is cancelled and not given to the executor.cleanUp()of the mailbox cache. The cache expires a mailbox 300 s after the last lookup, not the last read. So a periodic clean-up would cancel the mailboxes of an exchange that runs longer than 300 s, also on quiet servers.Tests
QueryExecutionContextTest(new),QueryMultiThreadingUtilsTest,OpChainSchedulerServiceTest: the context does not keep done tasks, andterminate()still cancels the running ones.MailboxReceiveOperatorTest: after close, the mailboxes drop the thread context. Mailboxes of finished senders are released, and mailboxes of running senders stay.ReceivingMailboxTest: when the sender counts as finished.The 5 retention tests fail without the fix.