-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Fix handling of time exceeded exception in fetch phase #116676
Conversation
Pinging @elastic/es-search-foundations (Team:Search Foundations) |
Hi @javanna, I've created a changelog YAML for you. |
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.
LGTM
server/src/main/java/org/elasticsearch/search/fetch/FetchPhaseDocsIterator.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/action/search/FetchSearchPhaseTests.java
Outdated
Show resolved
Hide resolved
The fetch phase is subject to timeouts like any other search phase. Timeouts may happen when low level cancellation is enabled (true by default), hence the directory reader is wrapped into ExitableDirectoryReader and a timeout is provided to the search request. The exception that is used is TimeExceededException, but it is an internal exception that should never be returned to the user. When that is thrown, we need to catch it and throw error or mark the response as timed out depending on whether partial results are allowed or not.
5ad7e3e
to
4f38193
Compare
@@ -75,7 +75,7 @@ public void shardResult(SearchHits hits, ProfileResult profileResult) { | |||
|
|||
private static boolean assertNoSearchTarget(SearchHits hits) { | |||
for (SearchHit hit : hits.getHits()) { | |||
assert hit.getShard() == null : "expected null but got: " + hit.getShard(); | |||
assert hit == null || hit.getShard() == null : "expected null but got: " + hit.getShard(); |
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.
@original-brownbear I am not clear if this is introducing a potential bug. With a timeout, we now may have null items in the SearchHit array. I am not entirely sure whether that may cause issues down the line. I see also a similar assertion in the deallocate method that checks that all items are not null. Shall I relax that too or do you have a different idea in mind?
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.
Right, thanks for pointing this out + sorry for not spotting this.
Currently, this would sort of work but the output is slightly confusing and we'd have to add null checks to the deallocate method. Also UX-wise, the x-content serialization will contain JSON null
values in the hits array. We don't need that or even want that even do we?
Maybe we should just keep it simple and in case we run into a timeout create a new array with just the non-null elements? That seems like the low-risk simple solution that doesn't change anything about the SearchHits
instances and their users?
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.
This works well now, I also added a test to cover for the scenario where partial results are returned, those fetched until the timeout error was thrown.
The fetch phase is subject to timeouts like any other search phase. Timeouts may happen when low level cancellation is enabled (true by default), hence the directory reader is wrapped into ExitableDirectoryReader and a timeout is provided to the search request. The exception that is used is TimeExceededException, but it is an internal exception that should never be returned to the user. When that is thrown, we need to catch it and throw error or mark the response as timed out depending on whether partial results are allowed or not.
The fetch phase is subject to timeouts like any other search phase. Timeouts may happen when low level cancellation is enabled (true by default), hence the directory reader is wrapped into ExitableDirectoryReader and a timeout is provided to the search request. The exception that is used is TimeExceededException, but it is an internal exception that should never be returned to the user. When that is thrown, we need to catch it and throw error or mark the response as timed out depending on whether partial results are allowed or not.
The fetch phase is subject to timeouts like any other search phase. Timeouts may happen when low level cancellation is enabled (true by default), hence the directory reader is wrapped into ExitableDirectoryReader and a timeout is provided to the search request. The exception that is used is TimeExceededException, but it is an internal exception that should never be returned to the user. When that is thrown, we need to catch it and throw error or mark the response as timed out depending on whether partial results are allowed or not.
The fetch phase is subject to timeouts like any other search phase. Timeouts may happen when low level cancellation is enabled (true by default), hence the directory reader is wrapped into ExitableDirectoryReader and a timeout is provided to the search request. The exception that is used is TimeExceededException, but it is an internal exception that should never be returned to the user. When that is thrown, we need to catch it and throw error or mark the response as timed out depending on whether partial results are allowed or not.
The fetch phase is subject to timeouts like any other search phase. Timeouts may happen when low level cancellation is enabled (true by default), hence the directory reader is wrapped into ExitableDirectoryReader and a timeout is provided to the search request.
The exception that is used is TimeExceededException, but it is an internal exception that should never be returned to the user. When that is thrown, we need to catch it and throw error or mark the response as timed out depending on whether partial results are allowed or not.