From 1b030e7398d7325bf9c185b2a0cce34d7ccd7792 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Thu, 17 Sep 2020 15:38:36 -0400 Subject: [PATCH] Add an additional cancellation check to the fetch phase (#62577) In #62357 we introduced an additional optimization that allows us to skip the most of the fetch phase early if no results are found. This change caused some cancellation test failures that were relying on definitive cancellation during the fetch phase. This commit adds an additional quick cancellation check at the very beginning of the fetch phase to make cancellation process more deterministic. Fixes #62530 --- .../main/java/org/elasticsearch/search/fetch/FetchPhase.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java b/server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java index 208b20828fba8..4ca0f9cf290c5 100644 --- a/server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java +++ b/server/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java @@ -91,6 +91,10 @@ public void execute(SearchContext context) { LOGGER.trace("{}", new SearchContextSourcePrinter(context)); } + if (context.isCancelled()) { + throw new TaskCancelledException("cancelled"); + } + if (context.docIdsToLoadSize() == 0) { // no individual hits to process, so we shortcut context.fetchResult().hits(new SearchHits(new SearchHit[0], context.queryResult().getTotalHits(),