Skip to content

Commit 379d995

Browse files
authored
Fix SearchProgressActionListenerIT (#120888) (#121019)
This fixes SearchProgressActionListenerIT by notifying the search progress listener before search operation terminates. (cherry picked from commit cbb62c2) Signed-off-by: Andrei Dan <[email protected]>
1 parent b2b06cb commit 379d995

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,6 @@ tests:
438438
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
439439
method: test {p0=transform/transforms_start_stop/Test schedule_now on an already started transform}
440440
issue: https://github.com/elastic/elasticsearch/issues/120720
441-
- class: org.elasticsearch.action.search.SearchProgressActionListenerIT
442-
method: testSearchProgressWithHitsAndAggs
443-
issue: https://github.com/elastic/elasticsearch/issues/120583
444441
- class: org.elasticsearch.xpack.esql.action.CrossClusterAsyncEnrichStopIT
445442
method: testEnrichAfterStop
446443
issue: https://github.com/elastic/elasticsearch/issues/120757

server/src/main/java/org/elasticsearch/action/search/FetchSearchPhase.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,21 @@ private void innerRunFetch(ScoreDoc[] scoreDocs, int numShards, SearchPhaseContr
155155
);
156156
for (int i = 0; i < docIdsToLoad.length; i++) {
157157
List<Integer> entry = docIdsToLoad[i];
158+
SearchPhaseResult shardPhaseResult = searchPhaseShardResults.get(i);
158159
if (entry == null) { // no results for this shard ID
159160
// if we got some hits from this shard we have to release the context
160161
// we do this below after sending out the fetch requests relevant to the search to give priority to those requests
161162
// that contribute to the final search response
162163
// in any case we count down this result since we don't talk to this shard anymore
164+
if (shardPhaseResult != null) {
165+
// notifying the listener here as otherwise the search operation might finish before we
166+
// get a chance to notify the progress listener for some fetch results
167+
progressListener.notifyFetchResult(i);
168+
}
163169
counter.countDown();
164170
} else {
165171
executeFetch(
166-
searchPhaseShardResults.get(i),
172+
shardPhaseResult,
167173
counter,
168174
entry,
169175
rankDocsPerShard == null || rankDocsPerShard.get(i).isEmpty() ? null : new RankDocShardInfo(rankDocsPerShard.get(i)),
@@ -176,7 +182,6 @@ private void innerRunFetch(ScoreDoc[] scoreDocs, int numShards, SearchPhaseContr
176182
SearchPhaseResult shardPhaseResult = searchPhaseShardResults.get(i);
177183
if (shardPhaseResult != null) {
178184
releaseIrrelevantSearchContext(shardPhaseResult, context);
179-
progressListener.notifyFetchResult(i);
180185
}
181186
}
182187
}

0 commit comments

Comments
 (0)