diff --git a/docs/changelog/132334.yaml b/docs/changelog/132334.yaml new file mode 100644 index 0000000000000..b734e5a792991 --- /dev/null +++ b/docs/changelog/132334.yaml @@ -0,0 +1,6 @@ +pr: 132334 +summary: Do not look over `TaskCancelledException` when looking at failures while + updating CCS info for clusters +area: CCS +type: bug +issues: [] diff --git a/muted-tests.yml b/muted-tests.yml index a2e33d9d1fc6b..cfb19bc98b004 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -292,9 +292,6 @@ tests: issue: https://github.com/elastic/elasticsearch/issues/117591 - class: org.elasticsearch.repositories.s3.RepositoryS3ClientYamlTestSuiteIT issue: https://github.com/elastic/elasticsearch/issues/117596 -- class: org.elasticsearch.search.ccs.CrossClusterIT - method: testCancel - issue: https://github.com/elastic/elasticsearch/issues/108061 - class: org.elasticsearch.xpack.ml.integration.RegressionIT method: testTwoJobsWithSameRandomizeSeedUseSameTrainingSet issue: https://github.com/elastic/elasticsearch/issues/117805 diff --git a/server/src/main/java/org/elasticsearch/ExceptionsHelper.java b/server/src/main/java/org/elasticsearch/ExceptionsHelper.java index ec04b63a575db..e2e61d78024f2 100644 --- a/server/src/main/java/org/elasticsearch/ExceptionsHelper.java +++ b/server/src/main/java/org/elasticsearch/ExceptionsHelper.java @@ -19,6 +19,7 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.index.Index; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.tasks.TaskCancelledException; import org.elasticsearch.transport.ConnectTransportException; import org.elasticsearch.transport.NoSeedNodeLeftException; import org.elasticsearch.transport.NoSuchRemoteClusterException; @@ -514,6 +515,15 @@ public static boolean isRemoteUnavailableException(Exception e) { return false; } + /** + * Utility method to check if an Exception is/was caused by TaskCancelledException. + * @param e Exception we're interested in evaluating. + * @return true if the Exception is/was caused by TaskCancelledException, else false. + */ + public static boolean isTaskCancelledException(Exception e) { + return ExceptionsHelper.unwrapCausesAndSuppressed(e, ex -> ex instanceof TaskCancelledException).isPresent(); + } + private static class GroupBy { final String reason; final String index; diff --git a/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java b/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java index 219e4a78ace46..54f978ec1597b 100644 --- a/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java @@ -40,7 +40,6 @@ import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.ShardSearchContextId; import org.elasticsearch.search.internal.ShardSearchRequest; -import org.elasticsearch.tasks.TaskCancelledException; import org.elasticsearch.transport.Transport; import java.util.ArrayList; @@ -518,7 +517,7 @@ void onShardFailure(final int shardIndex, SearchShardTarget shardTarget, Excepti } // we don't aggregate shard on failures due to the internal cancellation, // but do keep the header counts right - if ((requestCancelled.get() && isTaskCancelledException(e)) == false) { + if ((requestCancelled.get() && ExceptionsHelper.isTaskCancelledException(e)) == false) { AtomicArray shardFailures = this.shardFailures.get(); // lazily create shard failures, so we can early build the empty shard failure list in most cases (no failures) if (shardFailures == null) { // this is double checked locking but it's fine since SetOnce uses a volatile read internally @@ -549,10 +548,6 @@ void onShardFailure(final int shardIndex, SearchShardTarget shardTarget, Excepti results.consumeShardFailure(shardIndex); } - private static boolean isTaskCancelledException(Exception e) { - return ExceptionsHelper.unwrapCausesAndSuppressed(e, ex -> ex instanceof TaskCancelledException).isPresent(); - } - /** * Executed once for every successful shard level request. * @param result the result returned form the shard diff --git a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index 2f0fcb1599724..6dc24bdd9f1f7 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -1707,7 +1707,7 @@ public final void onFailure(Exception e) { ShardSearchFailure f = new ShardSearchFailure(e); logCCSError(f, clusterAlias, skipUnavailable); SearchResponse.Cluster cluster = clusters.getCluster(clusterAlias); - if (skipUnavailable) { + if (skipUnavailable && ExceptionsHelper.isTaskCancelledException(e) == false) { if (cluster != null) { ccsClusterInfoUpdate(f, clusters, clusterAlias, true); } @@ -1716,7 +1716,8 @@ public final void onFailure(Exception e) { ccsClusterInfoUpdate(f, clusters, clusterAlias, false); } Exception exception = e; - if (RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY.equals(clusterAlias) == false) { + if (RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY.equals(clusterAlias) == false + && ExceptionsHelper.isTaskCancelledException(e) == false) { exception = wrapRemoteClusterFailure(clusterAlias, e); } if (exceptions.compareAndSet(null, exception) == false) {