Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/102715.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 102715
summary: Fix leaking blocks in TopN
area: ES|QL
type: bug
issues:
- 102646
Original file line number Diff line number Diff line change
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