Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release memory held by aggs on failure #72966

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ public void consume(QuerySearchResult result, Runnable next) {
addEstimateAndMaybeBreak(aggsSize);
} catch (Exception exc) {
result.releaseAggs();
buffer.forEach(QuerySearchResult::releaseAggs);
buffer.clear();
onMergeFailure(exc);
next.run();
return;
Expand Down Expand Up @@ -402,17 +404,20 @@ protected void doRun() {
final MergeResult thisMergeResult = mergeResult;
long estimatedTotalSize = (thisMergeResult != null ? thisMergeResult.estimatedSize : 0) + task.aggsBufferSize;
final MergeResult newMerge;
final QuerySearchResult[] toConsume = task.consumeBuffer();
if (toConsume == null) {
return;
}
try {
final QuerySearchResult[] toConsume = task.consumeBuffer();
if (toConsume == null) {
return;
}
long estimatedMergeSize = estimateRamBytesUsedForReduce(estimatedTotalSize);
addEstimateAndMaybeBreak(estimatedMergeSize);
estimatedTotalSize += estimatedMergeSize;
++ numReducePhases;
newMerge = partialReduce(toConsume, task.emptyResults, topDocsStats, thisMergeResult, numReducePhases);
} catch (Exception t) {
for (QuerySearchResult result : toConsume) {
result.releaseAggs();
}
onMergeFailure(t);
return;
}
Expand Down Expand Up @@ -507,7 +512,12 @@ public void consumeListener() {
}

public synchronized void cancel() {
consumeBuffer();
QuerySearchResult[] buffer = consumeBuffer();
if (buffer != null) {
for (QuerySearchResult result : buffer) {
result.releaseAggs();
}
}
consumeListener();
}
}
Expand Down