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

ESQL: Page shouldn't close a block twice #100370

Merged
merged 6 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions docs/changelog/100370.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pr: 100370
summary: "ESQL: Page shouldn't close a block twice"
area: ES|QL
type: bug
issues:
- 100356
- 100365
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.IdentityHashMap;
import java.util.Objects;

/**
Expand Down Expand Up @@ -169,8 +170,8 @@ public Page appendPage(Page toAdd) {
@Override
public int hashCode() {
int result = Objects.hash(positionCount);
for (int i = 0; i < blocks.length; i++) {
result = 31 * result + Objects.hashCode(blocks[i]);
for (Block block : blocks) {
result = 31 * result + Objects.hashCode(block);
}
return result;
}
Expand Down Expand Up @@ -222,6 +223,13 @@ public void writeTo(StreamOutput out) throws IOException {
*/
public void releaseBlocks() {
blocksReleased = true;
Releasables.closeExpectNoException(blocks);
// blocks can be used as multiple columns
var set = new IdentityHashMap<Block, Object>();
Copy link
Member

Choose a reason for hiding this comment

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

Collections.newSetFromMap is the idiomatic way to do this. And all the cool kids want to be idiots, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

:)
I actually tried that first but it blew up because the blocks equals implementation checks the content meaning different blocks end up looking equal meaning they are not closed as they are considered a duplicate.
Which causes a bunch of leaks - hence why I'm using the Identity match alone.

var DUMMY = new Object();
Copy link
Contributor

Choose a reason for hiding this comment

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

That could be moved into a static final var.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or...

var map = new IdentityHashMap<Block, Boolean>(mapSize(blocks.length));
for (Block b : blocks) {
    if (map.putIfAbsent(b, Boolean.TRUE) == null) { ..

for (Block b : blocks) {
if (set.putIfAbsent(b, DUMMY) == null) {
Releasables.closeExpectNoException(b);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ x:integer | z:integer
4 | 8
;

# AwaitsFix https://github.com/elastic/elasticsearch/issues/100356
renameProjectEval-Ignore
renameProjectEval
from employees | sort emp_no | eval y = languages | rename languages as x | keep x, y | eval x2 = x + 1 | eval y2 = y + 2 | limit 3;

x:integer | y:integer | x2:integer | y2:integer
Expand All @@ -94,8 +93,7 @@ x:integer | y:integer | x2:integer | y2:integer
4 | 4 | 5 | 6
;

# AwaitsFix https://github.com/elastic/elasticsearch/issues/100356
duplicateProjectEval-Ignore
duplicateProjectEval
from employees | eval y = languages, x = languages | keep x, y | eval x2 = x + 1 | eval y2 = y + 2 | limit 3;

x:integer | y:integer | x2:integer | y2:integer
Expand Down Expand Up @@ -160,8 +158,7 @@ y:integer | x:date
10061 | 1985-09-17T00:00:00.000Z
;

# AwaitsFix https://github.com/elastic/elasticsearch/issues/100356
renameIntertwinedWithSort-Ignore
renameIntertwinedWithSort
FROM employees | eval x = salary | rename x as y | rename y as x | sort x | rename x as y | limit 10;

avg_worked_seconds:l | birth_date:date | emp_no:i | first_name:s | gender:s | height:d | height.float:d | height.half_float:d | height.scaled_float:d| hire_date:date | is_rehired:bool | job_positions:s | languages:i | languages.byte:i | languages.long:l | languages.short:i | last_name:s | salary:i | salary_change:d | salary_change.int:i | salary_change.keyword:s | salary_change.long:l | still_hired:bool | y:i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package org.elasticsearch.xpack.esql.action;

import org.apache.lucene.tests.util.LuceneTestCase;
import org.elasticsearch.Build;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
Expand Down Expand Up @@ -67,7 +66,6 @@
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.nullValue;

@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/100365")
public class EsqlActionIT extends AbstractEsqlIntegTestCase {

long epoch = System.currentTimeMillis();
Expand Down