-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Address CompoundRetrieverBuilder Failure Handling #136732
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
Open
john-wagster
wants to merge
9
commits into
elastic:main
Choose a base branch
from
john-wagster:better_retriever_errors_on_shard_failure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+81
−3
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
888b6e5
added a check for shard failures
john-wagster 169d4f5
spotless
john-wagster 4ed8ca2
passing back message and status code from each failed shard instead
john-wagster ababf26
added a mock test for now to at least get some coverage / validation …
john-wagster aa7f868
spotless
john-wagster 211ce84
Merge branch 'main' into better_retriever_errors_on_shard_failure
john-wagster c1f8cd5
Update docs/changelog/136732.yaml
john-wagster 30597dc
add issue
john-wagster c0c467b
Update docs/changelog/136732.yaml
john-wagster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 136732 | ||
summary: Address `CompoundRetrieverBuilder` Failure Handling | ||
area: Search | ||
type: bug | ||
issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import org.elasticsearch.action.search.MultiSearchResponse; | ||
import org.elasticsearch.action.search.SearchRequest; | ||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.action.search.ShardSearchFailure; | ||
import org.elasticsearch.action.search.TransportMultiSearchAction; | ||
import org.elasticsearch.features.NodeFeature; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
|
@@ -174,9 +175,13 @@ public void onResponse(MultiSearchResponse items) { | |
} | ||
} else { | ||
assert item.getResponse() != null; | ||
var rankDocs = getRankDocs(item.getResponse()); | ||
innerRetrievers.get(i).retriever().setRankDocs(rankDocs); | ||
topDocs.add(rankDocs); | ||
if (item.getResponse().getFailedShards() > 0) { | ||
statusCode = handleShardFailures(item.getResponse(), statusCode, failures); | ||
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. Hey, by default, we allow partial results and return a 2xx. Does this break that? Meaning, if there is a failed shard, do we still return a 2xx by default? We should:
|
||
} else { | ||
var rankDocs = getRankDocs(item.getResponse()); | ||
innerRetrievers.get(i).retriever().setRankDocs(rankDocs); | ||
topDocs.add(rankDocs); | ||
} | ||
} | ||
} | ||
if (false == failures.isEmpty()) { | ||
|
@@ -212,6 +217,26 @@ public void onFailure(Exception e) { | |
return rankDocsRetrieverBuilder; | ||
} | ||
|
||
static int handleShardFailures(SearchResponse response, int statusCode, List<Exception> failures) { | ||
ShardSearchFailure[] shardFailures = response.getShardFailures(); | ||
for (ShardSearchFailure shardFailure : shardFailures) { | ||
if (shardFailure != null) { | ||
int shardFailureStatusCode = ExceptionsHelper.status(shardFailure.getCause()).getStatus(); | ||
failures.add( | ||
new ElasticsearchStatusException( | ||
"failed to retrieve data from shard [" | ||
+ shardFailure.shardId() | ||
+ "] with message: " | ||
+ shardFailure.getCause().getMessage(), | ||
RestStatus.fromCode(shardFailureStatusCode) | ||
) | ||
); | ||
statusCode = Math.max(shardFailureStatusCode, statusCode); | ||
} | ||
} | ||
return statusCode; | ||
} | ||
|
||
@Override | ||
public final QueryBuilder topDocsQuery() { | ||
throw new IllegalStateException("Should not be called, missing a rewrite?"); | ||
|
48 changes: 48 additions & 0 deletions
48
server/src/test/java/org/elasticsearch/search/retriever/CompoundRetrieverBuilderTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.search.retriever; | ||
|
||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.action.search.ShardSearchFailure; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.search.SearchShardTarget; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
public class CompoundRetrieverBuilderTests extends ESTestCase { | ||
public void testShardFailureHandling() { | ||
SearchResponse response = Mockito.mock(SearchResponse.class); | ||
ShardSearchFailure[] shardFailures = new ShardSearchFailure[2]; | ||
shardFailures[0] = new ShardSearchFailure( | ||
new IOException("some shard failed"), // 500 | ||
new SearchShardTarget("1", new ShardId("1", "1", 1), "foo") | ||
); | ||
shardFailures[1] = new ShardSearchFailure( | ||
new IOException("some second shard failed"), // 500 | ||
new SearchShardTarget("2", new ShardId("2", "2", 2), "bar") | ||
); | ||
when(response.getShardFailures()).thenReturn(shardFailures); | ||
|
||
int priorStatusCode = randomIntBetween(200, 600); | ||
List<Exception> failures = new ArrayList<>(); | ||
int shardFailureStatusCode = CompoundRetrieverBuilder.handleShardFailures(response, priorStatusCode, failures); | ||
|
||
assertEquals(2, failures.size()); | ||
assertEquals("failed to retrieve data from shard [1] with message: some shard failed", failures.get(0).getMessage()); | ||
assertEquals("failed to retrieve data from shard [2] with message: some second shard failed", failures.get(1).getMessage()); | ||
assertEquals(Math.max(priorStatusCode, 500), shardFailureStatusCode); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.