Skip to content

Commit 056ec71

Browse files
[8.x] Do not look over TaskCancelledException when looking at failures when updating CCS info for clusters (#125206) (#125237)
* Do not look over `TaskCancelledException` when looking at failures when updating CCS info for clusters (#125206) Do not look over `TaskCancelledException` when looking at failures when updating CCS info for clusters (cherry picked from commit 0350a48) # Conflicts: # muted-tests.yml * Fix conflict
1 parent 1b22b0e commit 056ec71

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

muted-tests.yml

-3
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,6 @@ tests:
291291
issue: https://github.com/elastic/elasticsearch/issues/117591
292292
- class: org.elasticsearch.repositories.s3.RepositoryS3ClientYamlTestSuiteIT
293293
issue: https://github.com/elastic/elasticsearch/issues/117596
294-
- class: org.elasticsearch.search.ccs.CrossClusterIT
295-
method: testCancel
296-
issue: https://github.com/elastic/elasticsearch/issues/108061
297294
- class: org.elasticsearch.xpack.ml.integration.RegressionIT
298295
method: testTwoJobsWithSameRandomizeSeedUseSameTrainingSet
299296
issue: https://github.com/elastic/elasticsearch/issues/117805

server/src/main/java/org/elasticsearch/ExceptionsHelper.java

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.core.Nullable;
2020
import org.elasticsearch.index.Index;
2121
import org.elasticsearch.rest.RestStatus;
22+
import org.elasticsearch.tasks.TaskCancelledException;
2223
import org.elasticsearch.transport.ConnectTransportException;
2324
import org.elasticsearch.transport.NoSeedNodeLeftException;
2425
import org.elasticsearch.transport.NoSuchRemoteClusterException;
@@ -514,6 +515,15 @@ public static boolean isRemoteUnavailableException(Exception e) {
514515
return false;
515516
}
516517

518+
/**
519+
* Utility method to check if an Exception is/was caused by TaskCancelledException.
520+
* @param e Exception we're interested in evaluating.
521+
* @return true if the Exception is/was caused by TaskCancelledException, else false.
522+
*/
523+
public static boolean isTaskCancelledException(Exception e) {
524+
return ExceptionsHelper.unwrapCausesAndSuppressed(e, ex -> ex instanceof TaskCancelledException).isPresent();
525+
}
526+
517527
private static class GroupBy {
518528
final String reason;
519529
final String index;

server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.elasticsearch.search.internal.SearchContext;
3939
import org.elasticsearch.search.internal.ShardSearchContextId;
4040
import org.elasticsearch.search.internal.ShardSearchRequest;
41-
import org.elasticsearch.tasks.TaskCancelledException;
4241
import org.elasticsearch.transport.Transport;
4342

4443
import java.util.ArrayList;
@@ -505,7 +504,7 @@ void onShardFailure(final int shardIndex, SearchShardTarget shardTarget, Excepti
505504
}
506505
// we don't aggregate shard on failures due to the internal cancellation,
507506
// but do keep the header counts right
508-
if ((requestCancelled.get() && isTaskCancelledException(e)) == false) {
507+
if ((requestCancelled.get() && ExceptionsHelper.isTaskCancelledException(e)) == false) {
509508
AtomicArray<ShardSearchFailure> shardFailures = this.shardFailures.get();
510509
// lazily create shard failures, so we can early build the empty shard failure list in most cases (no failures)
511510
if (shardFailures == null) { // this is double checked locking but it's fine since SetOnce uses a volatile read internally
@@ -535,10 +534,6 @@ void onShardFailure(final int shardIndex, SearchShardTarget shardTarget, Excepti
535534
}
536535
}
537536

538-
private static boolean isTaskCancelledException(Exception e) {
539-
return ExceptionsHelper.unwrapCausesAndSuppressed(e, ex -> ex instanceof TaskCancelledException).isPresent();
540-
}
541-
542537
/**
543538
* Executed once for every successful shard level request.
544539
* @param result the result returned form the shard

server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ public final void onFailure(Exception e) {
17091709
ShardSearchFailure f = new ShardSearchFailure(e);
17101710
logCCSError(f, clusterAlias, skipUnavailable);
17111711
SearchResponse.Cluster cluster = clusters.getCluster(clusterAlias);
1712-
if (skipUnavailable) {
1712+
if (skipUnavailable && ExceptionsHelper.isTaskCancelledException(e) == false) {
17131713
if (cluster != null) {
17141714
ccsClusterInfoUpdate(f, clusters, clusterAlias, true);
17151715
}
@@ -1718,7 +1718,8 @@ public final void onFailure(Exception e) {
17181718
ccsClusterInfoUpdate(f, clusters, clusterAlias, false);
17191719
}
17201720
Exception exception = e;
1721-
if (RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY.equals(clusterAlias) == false) {
1721+
if (RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY.equals(clusterAlias) == false
1722+
&& ExceptionsHelper.isTaskCancelledException(e) == false) {
17221723
exception = wrapRemoteClusterFailure(clusterAlias, e);
17231724
}
17241725
if (exceptions.compareAndSet(null, exception) == false) {

0 commit comments

Comments
 (0)