Skip to content
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

Merged
merged 7 commits into from
Nov 18, 2024

Conversation

javanna
Copy link
Member

@javanna javanna commented Nov 12, 2024

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.

@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Nov 12, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@javanna javanna added the >bug label Nov 12, 2024
@elasticsearchmachine
Copy link
Collaborator

Hi @javanna, I've created a changelog YAML for you.

Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@javanna javanna requested review from a team as code owners November 12, 2024 18:07
javanna and others added 3 commits November 12, 2024 19:08
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.
@javanna javanna removed request for a team November 12, 2024 18:09
@@ -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();
Copy link
Member Author

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?

Copy link
Member

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?

Copy link
Member Author

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.

@javanna javanna merged commit 366fa74 into elastic:main Nov 18, 2024
16 checks passed
@javanna javanna deleted the fix/time_exceeded_fetch branch November 18, 2024 12:17
javanna added a commit to javanna/elasticsearch that referenced this pull request Nov 18, 2024
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.
javanna added a commit to javanna/elasticsearch that referenced this pull request Nov 18, 2024
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.
javanna added a commit that referenced this pull request Nov 18, 2024
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.
javanna added a commit that referenced this pull request Nov 18, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v8.16.1 v8.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants