Skip to content

Commit f9adb16

Browse files
Do not look over TaskCancelledException when looking at failures while updating CCS info for clusters (#132334)
Do not look over `TaskCancelledException` when looking at failures while updating CCS info for clusters
1 parent 685cb59 commit f9adb16

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

docs/changelog/132334.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 132334
2+
summary: Do not look over `TaskCancelledException` when looking at failures while
3+
updating CCS info for clusters
4+
area: CCS
5+
type: bug
6+
issues: []

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,6 @@ tests:
292292
issue: https://github.com/elastic/elasticsearch/issues/117591
293293
- class: org.elasticsearch.repositories.s3.RepositoryS3ClientYamlTestSuiteIT
294294
issue: https://github.com/elastic/elasticsearch/issues/117596
295-
- class: org.elasticsearch.search.ccs.CrossClusterIT
296-
method: testCancel
297-
issue: https://github.com/elastic/elasticsearch/issues/108061
298295
- class: org.elasticsearch.xpack.ml.integration.RegressionIT
299296
method: testTwoJobsWithSameRandomizeSeedUseSameTrainingSet
300297
issue: https://github.com/elastic/elasticsearch/issues/117805

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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.elasticsearch.search.internal.SearchContext;
4141
import org.elasticsearch.search.internal.ShardSearchContextId;
4242
import org.elasticsearch.search.internal.ShardSearchRequest;
43-
import org.elasticsearch.tasks.TaskCancelledException;
4443
import org.elasticsearch.transport.Transport;
4544

4645
import java.util.ArrayList;
@@ -518,7 +517,7 @@ void onShardFailure(final int shardIndex, SearchShardTarget shardTarget, Excepti
518517
}
519518
// we don't aggregate shard on failures due to the internal cancellation,
520519
// but do keep the header counts right
521-
if ((requestCancelled.get() && isTaskCancelledException(e)) == false) {
520+
if ((requestCancelled.get() && ExceptionsHelper.isTaskCancelledException(e)) == false) {
522521
AtomicArray<ShardSearchFailure> shardFailures = this.shardFailures.get();
523522
// lazily create shard failures, so we can early build the empty shard failure list in most cases (no failures)
524523
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
549548
results.consumeShardFailure(shardIndex);
550549
}
551550

552-
private static boolean isTaskCancelledException(Exception e) {
553-
return ExceptionsHelper.unwrapCausesAndSuppressed(e, ex -> ex instanceof TaskCancelledException).isPresent();
554-
}
555-
556551
/**
557552
* Executed once for every successful shard level request.
558553
* @param result the result returned form the shard

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ public final void onFailure(Exception e) {
17071707
ShardSearchFailure f = new ShardSearchFailure(e);
17081708
logCCSError(f, clusterAlias, skipUnavailable);
17091709
SearchResponse.Cluster cluster = clusters.getCluster(clusterAlias);
1710-
if (skipUnavailable) {
1710+
if (skipUnavailable && ExceptionsHelper.isTaskCancelledException(e) == false) {
17111711
if (cluster != null) {
17121712
ccsClusterInfoUpdate(f, clusters, clusterAlias, true);
17131713
}
@@ -1716,7 +1716,8 @@ public final void onFailure(Exception e) {
17161716
ccsClusterInfoUpdate(f, clusters, clusterAlias, false);
17171717
}
17181718
Exception exception = e;
1719-
if (RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY.equals(clusterAlias) == false) {
1719+
if (RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY.equals(clusterAlias) == false
1720+
&& ExceptionsHelper.isTaskCancelledException(e) == false) {
17201721
exception = wrapRemoteClusterFailure(clusterAlias, e);
17211722
}
17221723
if (exceptions.compareAndSet(null, exception) == false) {

0 commit comments

Comments
 (0)