Skip to content

Commit 7be2bc4

Browse files
authored
Fix counting skipped shards with filters (#131737) (#131769)
* Fix counting skipped shards with filters (cherry picked from commit a345f56) # Conflicts: # x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClustersIT.java # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
1 parent 4e857c3 commit 7be2bc4

File tree

5 files changed

+47
-17
lines changed

5 files changed

+47
-17
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,6 @@ tests:
330330
- class: org.elasticsearch.xpack.search.CrossClusterAsyncSearchIT
331331
method: testCCSClusterDetailsWhereAllShardsSkippedInCanMatch
332332
issue: https://github.com/elastic/elasticsearch/issues/128418
333-
- class: org.elasticsearch.xpack.esql.action.CrossClusterQueryWithFiltersIT
334-
method: testTimestampFilterFromQuery
335-
issue: https://github.com/elastic/elasticsearch/issues/127332
336333
- class: org.elasticsearch.xpack.esql.plugin.DataNodeRequestSenderIT
337334
method: testSearchWhileRelocating
338335
issue: https://github.com/elastic/elasticsearch/issues/128500

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClustersIT.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ record Doc(int id, String color, long data) {
7272
List<Doc> localDocs = List.of();
7373
final String remoteIndex = "test-remote-index";
7474
List<Doc> remoteDocs = List.of();
75+
private Boolean shouldCheckShardCounts = null;
7576

7677
@Before
7778
public void setUpIndices() throws Exception {
@@ -164,6 +165,17 @@ private Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder reques
164165
}
165166
}
166167

168+
private boolean checkShardCounts() {
169+
if (shouldCheckShardCounts == null) {
170+
try {
171+
shouldCheckShardCounts = capabilitiesSupportedNewAndOld(List.of("correct_skipped_shard_count"));
172+
} catch (IOException e) {
173+
shouldCheckShardCounts = false;
174+
}
175+
}
176+
return shouldCheckShardCounts;
177+
}
178+
167179
private <C, V> void assertResultMapForLike(
168180
boolean includeCCSMetadata,
169181
Map<String, Object> result,
@@ -295,11 +307,16 @@ private void assertClusterDetailsMap(Map<String, Object> result, boolean remoteO
295307
assertThat(
296308
remoteClusterShards,
297309
matchesMap().entry("total", greaterThanOrEqualTo(0))
298-
.entry("successful", remoteClusterShards.get("total"))
310+
.entry("successful", greaterThanOrEqualTo(0))
299311
.entry("skipped", greaterThanOrEqualTo(0))
300312
.entry("failed", 0)
301313
);
302-
314+
if (checkShardCounts()) {
315+
assertThat(
316+
(int) remoteClusterShards.get("successful") + (int) remoteClusterShards.get("skipped"),
317+
equalTo(remoteClusterShards.get("total"))
318+
);
319+
}
303320
if (remoteOnly == false) {
304321
@SuppressWarnings("unchecked")
305322
Map<String, Object> localCluster = (Map<String, Object>) details.get("(local)");
@@ -313,10 +330,16 @@ private void assertClusterDetailsMap(Map<String, Object> result, boolean remoteO
313330
assertThat(
314331
localClusterShards,
315332
matchesMap().entry("total", greaterThanOrEqualTo(0))
316-
.entry("successful", localClusterShards.get("total"))
333+
.entry("successful", greaterThanOrEqualTo(0))
317334
.entry("skipped", greaterThanOrEqualTo(0))
318335
.entry("failed", 0)
319336
);
337+
if (checkShardCounts()) {
338+
assertThat(
339+
(int) localClusterShards.get("successful") + (int) localClusterShards.get("skipped"),
340+
equalTo(localClusterShards.get("total"))
341+
);
342+
}
320343
}
321344
}
322345

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/CrossClusterQueryWithFiltersIT.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ protected void assertClusterMetadata(EsqlExecutionInfo.Cluster clusterMetatata,
6262
protected void assertClusterMetadataSuccess(EsqlExecutionInfo.Cluster clusterMetatata, int shards, long took, String indexExpression) {
6363
assertClusterMetadata(clusterMetatata, took, indexExpression, Status.SUCCESSFUL);
6464
assertThat(clusterMetatata.getTotalShards(), equalTo(shards));
65-
assertThat(clusterMetatata.getSuccessfulShards(), equalTo(shards));
66-
assertThat(clusterMetatata.getSkippedShards(), equalTo(0));
65+
// We should have at least one successful shard for data
66+
assertThat(clusterMetatata.getSuccessfulShards(), greaterThanOrEqualTo(1));
67+
// Some shards may be skipped, but total sum of the shards should match up
68+
assertThat(clusterMetatata.getSkippedShards() + clusterMetatata.getSuccessfulShards(), equalTo(shards));
6769
}
6870

6971
protected void assertClusterMetadataNoShards(EsqlExecutionInfo.Cluster clusterMetatata, long took, String indexExpression) {
@@ -81,7 +83,7 @@ protected void assertClusterMetadataSkippedShards(
8183
) {
8284
assertClusterMetadata(clusterMetatata, took, indexExpression, Status.SUCCESSFUL);
8385
assertThat(clusterMetatata.getTotalShards(), equalTo(shards));
84-
assertThat(clusterMetatata.getSuccessfulShards(), equalTo(shards));
86+
assertThat(clusterMetatata.getSuccessfulShards(), equalTo(0));
8587
assertThat(clusterMetatata.getSkippedShards(), equalTo(shards));
8688
}
8789

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
@@ -1250,7 +1250,12 @@ public enum Cap {
12501250
* Forbid usage of brackets in unquoted index and enrich policy names
12511251
* https://github.com/elastic/elasticsearch/issues/130378
12521252
*/
1253-
NO_BRACKETS_IN_UNQUOTED_INDEX_NAMES;
1253+
NO_BRACKETS_IN_UNQUOTED_INDEX_NAMES,
1254+
1255+
/**
1256+
* Support correct counting of skipped shards.
1257+
*/
1258+
CORRECT_SKIPPED_SHARDS_COUNT;
12541259

12551260
private final boolean enabled;
12561261

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,20 @@ final void startComputeOnDataNodes(Set<String> concreteIndices, Runnable runOnTa
134134
var computeListener = new ComputeListener(
135135
transportService.getThreadPool(),
136136
runOnTaskFailure,
137-
listener.map(
138-
completionInfo -> new ComputeResponse(
137+
listener.map(completionInfo -> {
138+
final int totalSkipShards = targetShards.skippedShards() + skippedShards.get();
139+
final int failedShards = shardFailures.size();
140+
final int successfulShards = targetShards.totalShards() - totalSkipShards - failedShards;
141+
return new ComputeResponse(
139142
completionInfo,
140143
timeValueNanos(System.nanoTime() - startTimeInNanos),
141144
targetShards.totalShards(),
142-
targetShards.totalShards() - shardFailures.size() - skippedShards.get(),
143-
targetShards.skippedShards() + skippedShards.get(),
144-
shardFailures.size(),
145+
successfulShards,
146+
totalSkipShards,
147+
failedShards,
145148
selectFailures()
146-
)
147-
)
149+
);
150+
})
148151
)
149152
) {
150153
pendingShardIds.addAll(order(targetShards));

0 commit comments

Comments
 (0)