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: 0 additions & 6 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,9 @@ tests:
- class: org.elasticsearch.test.rest.yaml.CcsCommonYamlTestSuiteIT
method: test {p0=search/510_range_query_out_of_bounds/Test range query for half_float field with out of bounds upper limit}
issue: https://github.com/elastic/elasticsearch/issues/135365
- class: org.elasticsearch.xpack.esql.session.SessionUtilsTests
method: testFromPages
issue: https://github.com/elastic/elasticsearch/issues/135377
- class: org.elasticsearch.xpack.esql.expression.function.scalar.score.DecayTests
method: "testEvaluateBlockWithoutNulls {TestCase=<date_nanos>, <date_nanos>, <time_duration>, <_source> #12}"
issue: https://github.com/elastic/elasticsearch/issues/135394
- class: org.elasticsearch.xpack.esql.session.SessionUtilsTests
method: testCheckPagesBelowSize
issue: https://github.com/elastic/elasticsearch/issues/135398
- class: org.elasticsearch.upgrades.DataStreamsUpgradeIT
method: testDataStreamValidationDoesNotBreakUpgrade
issue: https://github.com/elastic/elasticsearch/issues/135406
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,39 +126,45 @@ private static PagesRec generatePageSet(BlockFactory blockFactory) {

// Generates a list of Pages with one BytesRef block, each of different positions, filled with random bytes.
private static PagesRec generatePages(int minBytes, int maxBytes, BlockFactory blockFactory) {
BytesRefBlock.Builder builder = blockFactory.newBytesRefBlockBuilder(maxBytes);

byte[] buffer = new byte[maxBytes];
List<Page> pages = new ArrayList<>();

int producedBytes = 0;
int producedRows = 0;
int rowsPerPage = randomIntBetween(1, 100);
int rows = 0;
while (producedBytes < maxBytes) {
int rowBytes = Math.min(randomIntBetween(1, maxBytes / minBytes), maxBytes - producedBytes);
byte[] rowValue = randomByteArrayOfLength(rowBytes);

builder.appendBytesRef(new BytesRef(rowValue));
System.arraycopy(rowValue, 0, buffer, producedBytes, rowBytes);

producedBytes += rowBytes;
rows++;

if (rows > rowsPerPage) {
BytesRefBlock.Builder builder = null;
try {
builder = blockFactory.newBytesRefBlockBuilder(maxBytes);

byte[] buffer = new byte[maxBytes];
List<Page> pages = new ArrayList<>();

int producedBytes = 0;
int producedRows = 0;
int rowsPerPage = randomIntBetween(1, 100);
int rows = 0;
while (producedBytes < maxBytes) {
int rowBytes = Math.min(randomIntBetween(1, maxBytes / minBytes), maxBytes - producedBytes);
byte[] rowValue = randomByteArrayOfLength(rowBytes);

builder.appendBytesRef(new BytesRef(rowValue));
System.arraycopy(rowValue, 0, buffer, producedBytes, rowBytes);

producedBytes += rowBytes;
rows++;

if (rows > rowsPerPage) {
producedRows += rows;
rows = 0;
enqueueBlock(builder, pages);
Releasables.close(builder);
builder = blockFactory.newBytesRefBlockBuilder(maxBytes);
rowsPerPage = randomIntBetween(1, 100);
}
}
if (rows > 0) {
producedRows += rows;
rows = 0;
enqueueBlock(builder, pages);
builder = blockFactory.newBytesRefBlockBuilder(maxBytes);
rowsPerPage = randomIntBetween(1, 100);
}
}
if (rows > 0) {
producedRows += rows;
enqueueBlock(builder, pages);
}

return new PagesRec(pages, buffer, producedBytes, producedRows);
return new PagesRec(pages, buffer, producedBytes, producedRows);
} finally {
Releasables.close(builder);
}
}

private BlockFactory blockFactory(long maxBytes) {
Expand All @@ -172,6 +178,5 @@ private BlockFactory blockFactory(long maxBytes) {
private static void enqueueBlock(BytesRefBlock.Builder builder, List<Page> pages) {
Block block = builder.build();
pages.add(new Page(block));
Releasables.close(builder);
Copy link
Contributor Author

@bpintea bpintea Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change only makes sure Releasables.close(builder) is always called for a created builder.
The instance when this didn't happen was when the if-condition within the loop applied just as the while-condition no longer did. In this case a new builder was created, but not released.

}
}