-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
Check for query cancellation during rewrite #53166
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,6 @@ | |
import org.apache.lucene.search.TopFieldDocs; | ||
import org.apache.lucene.search.TotalHits; | ||
import org.apache.lucene.search.Weight; | ||
import org.elasticsearch.action.search.SearchShardTask; | ||
import org.elasticsearch.common.Booleans; | ||
import org.elasticsearch.common.CheckedConsumer; | ||
import org.elasticsearch.common.lucene.Lucene; | ||
|
@@ -110,7 +109,23 @@ public QueryPhase() { | |
|
||
@Override | ||
public void preProcess(SearchContext context) { | ||
context.preProcess(true); | ||
final Runnable cancellation; | ||
if (context.lowLevelCancellation()) { | ||
cancellation = context.searcher().addQueryCancellation(() -> { | ||
if (context.getTask().isCancelled()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's get the task once outside of the runnable like we do below ? |
||
throw new TaskCancelledException("cancelled"); | ||
} | ||
}); | ||
} else { | ||
cancellation = null; | ||
} | ||
try { | ||
context.preProcess(true); | ||
} finally { | ||
if (cancellation != null) { | ||
context.searcher().removeQueryCancellation(cancellation); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -265,9 +280,8 @@ static boolean executeInternal(SearchContext searchContext) throws QueryPhaseExe | |
} | ||
|
||
if (searchContext.lowLevelCancellation()) { | ||
SearchShardTask task = searchContext.getTask(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a slight preference for this version. The |
||
searcher.addQueryCancellation(() -> { | ||
if (task.isCancelled()) { | ||
if (searchContext.getTask().isCancelled()) { | ||
throw new TaskCancelledException("cancelled"); | ||
} | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's safe to ignore this parameter. Let's leave it for now but I wonder if we should simply remove this setting in a follow up. @jpountz what do you think ? I can open an issue if you think this deserves a full discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the long term, I agree that we should remove it. The thing that isn't clear to me is how much it hurts terms-dict-intensive queries like
fuzzy
queries.