Skip to content

Commit 936fca2

Browse files
authored
Put shards failure under a cap flag (elastic#131371) (elastic#131389)
* Put shards failure under a cap flag (cherry picked from commit 0411940) # Conflicts: # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
1 parent 5bee7e7 commit 936fca2

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

test/external-modules/error-query/src/javaRestTest/java/org/elasticsearch/test/esql/EsqlPartialResultsIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ public void testFailureFromRemote() throws Exception {
214214
}
215215

216216
public void testAllShardsFailed() throws Exception {
217+
assumeTrue(
218+
"fail functionality is not enabled",
219+
clusterHasCapability("POST", "/_query", List.of(), List.of("fail_if_all_shards_fail")).orElse(false)
220+
);
217221
setupRemoteClusters();
218222
populateIndices();
219223
try {
@@ -232,6 +236,26 @@ public void testAllShardsFailed() throws Exception {
232236
}
233237
}
234238

239+
public void testAllShardsFailedOldBehavior() throws Exception {
240+
// TODO: drop this once we no longer support the old behavior
241+
assumeFalse(
242+
"fail functionality is enabled",
243+
clusterHasCapability("POST", "/_query", List.of(), List.of("fail_if_all_shards_fail")).orElse(false)
244+
);
245+
setupRemoteClusters();
246+
populateIndices();
247+
try {
248+
Request request = new Request("POST", "/_query");
249+
request.setJsonEntity("{\"query\": \"FROM " + "*:failing*" + " | LIMIT 100\"}");
250+
request.addParameter("allow_partial_results", "true");
251+
Response resp = client().performRequest(request);
252+
Map<String, Object> results = entityAsMap(resp);
253+
assertThat(results.get("is_partial"), equalTo(true));
254+
} finally {
255+
removeRemoteCluster();
256+
}
257+
}
258+
235259
private void setupRemoteClusters() throws IOException {
236260
String settings = String.format(Locale.ROOT, """
237261
{

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,12 @@ public enum Cap {
10301030
* Forbid usage of brackets in unquoted index and enrich policy names
10311031
* https://github.com/elastic/elasticsearch/issues/130378
10321032
*/
1033-
NO_BRACKETS_IN_UNQUOTED_INDEX_NAMES;
1033+
NO_BRACKETS_IN_UNQUOTED_INDEX_NAMES,
1034+
1035+
/**
1036+
* Fail if all shards fail
1037+
*/
1038+
FAIL_IF_ALL_SHARDS_FAIL(Build.current().isSnapshot());
10341039

10351040
private final boolean enabled;
10361041

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/ComputeService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.transport.TransportException;
4444
import org.elasticsearch.transport.TransportRequest;
4545
import org.elasticsearch.transport.TransportService;
46+
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
4647
import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo;
4748
import org.elasticsearch.xpack.esql.action.EsqlQueryAction;
4849
import org.elasticsearch.xpack.esql.core.expression.Attribute;
@@ -399,6 +400,9 @@ private static void updateExecutionInfoAfterCoordinatorOnlyQuery(EsqlExecutionIn
399400
* which doesn't consider the failures from the remote clusters when skip_unavailable is true.
400401
*/
401402
static void failIfAllShardsFailed(EsqlExecutionInfo execInfo, List<Page> finalResults) {
403+
if (EsqlCapabilities.Cap.FAIL_IF_ALL_SHARDS_FAIL.isEnabled() == false) {
404+
return;
405+
}
402406
// do not fail if any final result has results
403407
if (finalResults.stream().anyMatch(p -> p.getPositionCount() > 0)) {
404408
return;

0 commit comments

Comments
 (0)