Skip to content

Commit 0411940

Browse files
authored
Put shards failure under a cap flag (elastic#131371)
* Put shards failure under a cap flag
1 parent b57ee3b commit 0411940

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,11 @@ public enum Cap {
12631263
*/
12641264
NO_BRACKETS_IN_UNQUOTED_INDEX_NAMES,
12651265

1266+
/**
1267+
* Fail if all shards fail
1268+
*/
1269+
FAIL_IF_ALL_SHARDS_FAIL(Build.current().isSnapshot()),
1270+
12661271
/*
12671272
* Cosine vector similarity function
12681273
*/

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
@@ -47,6 +47,7 @@
4747
import org.elasticsearch.transport.RemoteClusterAware;
4848
import org.elasticsearch.transport.TransportException;
4949
import org.elasticsearch.transport.TransportService;
50+
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
5051
import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo;
5152
import org.elasticsearch.xpack.esql.action.EsqlQueryAction;
5253
import org.elasticsearch.xpack.esql.core.expression.Attribute;
@@ -548,6 +549,9 @@ private static void updateExecutionInfoAfterCoordinatorOnlyQuery(EsqlExecutionIn
548549
* which doesn't consider the failures from the remote clusters when skip_unavailable is true.
549550
*/
550551
static void failIfAllShardsFailed(EsqlExecutionInfo execInfo, List<Page> finalResults) {
552+
if (EsqlCapabilities.Cap.FAIL_IF_ALL_SHARDS_FAIL.isEnabled() == false) {
553+
return;
554+
}
551555
// do not fail if any final result has results
552556
if (finalResults.stream().anyMatch(p -> p.getPositionCount() > 0)) {
553557
return;

0 commit comments

Comments
 (0)