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

Fix leaking blocks in TopN #102715

Merged
merged 2 commits into from Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/102715.yaml
@@ -0,0 +1,6 @@
pr: 102715
summary: Fix leaking blocks in TopN
area: ES|QL
type: bug
issues:
- 102646
Expand Up @@ -11,6 +11,8 @@
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.BlockFactory;
import org.elasticsearch.compute.data.DocVector;
import org.elasticsearch.compute.data.IntVector;
import org.elasticsearch.core.Releasables;

class ResultBuilderForDoc implements ResultBuilder {
private final BlockFactory blockFactory;
Expand Down Expand Up @@ -42,12 +44,21 @@ public void decodeValue(BytesRef values) {

@Override
public Block build() {
return new DocVector(
blockFactory.newIntArrayVector(shards, position),
blockFactory.newIntArrayVector(segments, position),
blockFactory.newIntArrayVector(docs, position),
null
).asBlock();
boolean success = false;
IntVector shardsVector = null;
IntVector segmentsVector = null;
try {
shardsVector = blockFactory.newIntArrayVector(shards, position);
segmentsVector = blockFactory.newIntArrayVector(segments, position);
var docsVector = blockFactory.newIntArrayVector(docs, position);
var docsBlock = new DocVector(shardsVector, segmentsVector, docsVector, null).asBlock();
success = true;
return docsBlock;
} finally {
if (success == false) {
Releasables.closeExpectNoException(shardsVector, segmentsVector);
}
}
}

@Override
Expand Down