Skip to content

Commit 6e6c4df

Browse files
authored
ESQL: Fix bug in topn (#133601)
Fix a bug in our topn collector that was not deduplicating shardRefCounted.
1 parent 54a2472 commit 6e6c4df

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

docs/changelog/133601.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pr: 133601
2+
summary: Fix bug in topn
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 133600
7+
- 133574
8+
- 133607

muted-tests.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -627,24 +627,15 @@ tests:
627627
- class: org.elasticsearch.test.rest.yaml.RcsCcsCommonYamlTestSuiteIT
628628
method: test {p0=search/10_source_filtering/no filtering}
629629
issue: https://github.com/elastic/elasticsearch/issues/133561
630-
- class: org.elasticsearch.compute.lucene.LuceneTopNSourceOperatorTests
631-
method: testShardDataPartitioning
632-
issue: https://github.com/elastic/elasticsearch/issues/133574
633630
- class: org.elasticsearch.compute.data.BasicBlockTests
634631
method: testIntBlock
635632
issue: https://github.com/elastic/elasticsearch/issues/133596
636633
- class: org.elasticsearch.xpack.logsdb.patternedtext.PatternedTextFieldMapperTests
637634
method: testSyntheticSourceMany
638635
issue: https://github.com/elastic/elasticsearch/issues/133598
639-
- class: org.elasticsearch.compute.lucene.LuceneTopNSourceOperatorTests
640-
method: testWithCranky
641-
issue: https://github.com/elastic/elasticsearch/issues/133600
642636
- class: org.elasticsearch.compute.data.BasicBlockTests
643637
method: testDoubleBlock
644638
issue: https://github.com/elastic/elasticsearch/issues/133606
645-
- class: org.elasticsearch.compute.lucene.LuceneTopNSourceOperatorTests
646-
method: testShardDataPartitioningWithCranky
647-
issue: https://github.com/elastic/elasticsearch/issues/133607
648639
- class: org.elasticsearch.compute.data.BasicBlockTests
649640
method: testBooleanBlock
650641
issue: https://github.com/elastic/elasticsearch/issues/133608

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneTopNSourceOperator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ public String describe() {
108108
* Collected docs. {@code null} until we're {@link #emit(boolean)}.
109109
*/
110110
private ScoreDoc[] scoreDocs;
111+
112+
/**
113+
* {@link ShardRefCounted} for collected docs.
114+
*/
115+
private ShardRefCounted shardRefCounted;
116+
111117
/**
112118
* The offset in {@link #scoreDocs} of the next page.
113119
*/
@@ -142,6 +148,7 @@ public boolean isFinished() {
142148
public void finish() {
143149
doneCollecting = true;
144150
scoreDocs = null;
151+
shardRefCounted = null;
145152
assert isFinished();
146153
}
147154

@@ -202,6 +209,8 @@ private Page emit(boolean startEmitting) {
202209
offset = 0;
203210
if (perShardCollector != null) {
204211
scoreDocs = perShardCollector.collector.topDocs().scoreDocs;
212+
int shardId = perShardCollector.shardContext.index();
213+
shardRefCounted = new ShardRefCounted.Single(shardId, shardContextCounters.get(shardId));
205214
} else {
206215
scoreDocs = new ScoreDoc[0];
207216
}
@@ -239,7 +248,6 @@ private Page emit(boolean startEmitting) {
239248
shard = blockFactory.newConstantIntBlockWith(shardId, size);
240249
segments = currentSegmentBuilder.build();
241250
docs = currentDocsBuilder.build();
242-
ShardRefCounted shardRefCounted = new ShardRefCounted.Single(shardId, shardContextCounters.get(shardId));
243251
docBlock = new DocVector(shardRefCounted, shard.asVector(), segments, docs, null).asBlock();
244252
shard = null;
245253
segments = null;

0 commit comments

Comments
 (0)