Skip to content

Commit c1a2219

Browse files
Do not look over TaskCancelledException when looking at failures when updating CCS info for clusters (#125206) (#125234)
Do not look over `TaskCancelledException` when looking at failures when updating CCS info for clusters
1 parent b3ce051 commit c1a2219

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ tests:
167167
- class: org.elasticsearch.xpack.ccr.FollowIndexSecurityIT
168168
method: testCleanShardFollowTaskAfterDeleteFollower
169169
issue: https://github.com/elastic/elasticsearch/issues/120339
170-
- class: org.elasticsearch.search.ccs.CrossClusterIT
171-
method: testCancel
172-
issue: https://github.com/elastic/elasticsearch/issues/108061
173170
- class: org.elasticsearch.reservedstate.service.FileSettingsServiceTests
174171
method: testInvalidJSON
175172
issue: https://github.com/elastic/elasticsearch/issues/120482

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
@@ -39,7 +39,6 @@
3939
import org.elasticsearch.search.internal.SearchContext;
4040
import org.elasticsearch.search.internal.ShardSearchContextId;
4141
import org.elasticsearch.search.internal.ShardSearchRequest;
42-
import org.elasticsearch.tasks.TaskCancelledException;
4342
import org.elasticsearch.transport.Transport;
4443

4544
import java.util.ArrayList;
@@ -462,7 +461,7 @@ void onShardFailure(final int shardIndex, SearchShardTarget shardTarget, Excepti
462461
}
463462
// we don't aggregate shard on failures due to the internal cancellation,
464463
// but do keep the header counts right
465-
if ((requestCancelled.get() && isTaskCancelledException(e)) == false) {
464+
if ((requestCancelled.get() && ExceptionsHelper.isTaskCancelledException(e)) == false) {
466465
AtomicArray<ShardSearchFailure> shardFailures = this.shardFailures.get();
467466
// lazily create shard failures, so we can early build the empty shard failure list in most cases (no failures)
468467
if (shardFailures == null) { // this is double checked locking but it's fine since SetOnce uses a volatile read internally
@@ -492,10 +491,6 @@ void onShardFailure(final int shardIndex, SearchShardTarget shardTarget, Excepti
492491
}
493492
}
494493

495-
private static boolean isTaskCancelledException(Exception e) {
496-
return ExceptionsHelper.unwrapCausesAndSuppressed(e, ex -> ex instanceof TaskCancelledException).isPresent();
497-
}
498-
499494
/**
500495
* Executed once for every successful shard level request.
501496
* @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
@@ -1708,7 +1708,7 @@ public final void onFailure(Exception e) {
17081708
ShardSearchFailure f = new ShardSearchFailure(e);
17091709
logCCSError(f, clusterAlias, skipUnavailable);
17101710
SearchResponse.Cluster cluster = clusters.getCluster(clusterAlias);
1711-
if (skipUnavailable) {
1711+
if (skipUnavailable && ExceptionsHelper.isTaskCancelledException(e) == false) {
17121712
if (cluster != null) {
17131713
ccsClusterInfoUpdate(f, clusters, clusterAlias, true);
17141714
}
@@ -1717,7 +1717,8 @@ public final void onFailure(Exception e) {
17171717
ccsClusterInfoUpdate(f, clusters, clusterAlias, false);
17181718
}
17191719
Exception exception = e;
1720-
if (RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY.equals(clusterAlias) == false) {
1720+
if (RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY.equals(clusterAlias) == false
1721+
&& ExceptionsHelper.isTaskCancelledException(e) == false) {
17211722
exception = wrapRemoteClusterFailure(clusterAlias, e);
17221723
}
17231724
if (exceptions.compareAndSet(null, exception) == false) {

0 commit comments

Comments
 (0)