Skip to content

Commit 0350a48

Browse files
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
1 parent 00c8ad8 commit 0350a48

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
@@ -158,9 +158,6 @@ tests:
158158
- class: org.elasticsearch.xpack.ccr.FollowIndexSecurityIT
159159
method: testCleanShardFollowTaskAfterDeleteFollower
160160
issue: https://github.com/elastic/elasticsearch/issues/120339
161-
- class: org.elasticsearch.search.ccs.CrossClusterIT
162-
method: testCancel
163-
issue: https://github.com/elastic/elasticsearch/issues/108061
164161
- class: org.elasticsearch.reservedstate.service.FileSettingsServiceTests
165162
method: testInvalidJSON
166163
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
@@ -36,7 +36,6 @@
3636
import org.elasticsearch.search.internal.SearchContext;
3737
import org.elasticsearch.search.internal.ShardSearchContextId;
3838
import org.elasticsearch.search.internal.ShardSearchRequest;
39-
import org.elasticsearch.tasks.TaskCancelledException;
4039
import org.elasticsearch.transport.Transport;
4140

4241
import java.util.ArrayList;
@@ -453,7 +452,7 @@ void onShardFailure(final int shardIndex, SearchShardTarget shardTarget, Excepti
453452
}
454453
// we don't aggregate shard on failures due to the internal cancellation,
455454
// but do keep the header counts right
456-
if ((requestCancelled.get() && isTaskCancelledException(e)) == false) {
455+
if ((requestCancelled.get() && ExceptionsHelper.isTaskCancelledException(e)) == false) {
457456
AtomicArray<ShardSearchFailure> shardFailures = this.shardFailures.get();
458457
// lazily create shard failures, so we can early build the empty shard failure list in most cases (no failures)
459458
if (shardFailures == null) { // this is double checked locking but it's fine since SetOnce uses a volatile read internally
@@ -483,10 +482,6 @@ void onShardFailure(final int shardIndex, SearchShardTarget shardTarget, Excepti
483482
}
484483
}
485484

486-
private static boolean isTaskCancelledException(Exception e) {
487-
return ExceptionsHelper.unwrapCausesAndSuppressed(e, ex -> ex instanceof TaskCancelledException).isPresent();
488-
}
489-
490485
/**
491486
* Executed once for every successful shard level request.
492487
* @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
@@ -1716,7 +1716,7 @@ public final void onFailure(Exception e) {
17161716
ShardSearchFailure f = new ShardSearchFailure(e);
17171717
logCCSError(f, clusterAlias, skipUnavailable);
17181718
SearchResponse.Cluster cluster = clusters.getCluster(clusterAlias);
1719-
if (skipUnavailable) {
1719+
if (skipUnavailable && ExceptionsHelper.isTaskCancelledException(e) == false) {
17201720
if (cluster != null) {
17211721
ccsClusterInfoUpdate(f, clusters, clusterAlias, true);
17221722
}
@@ -1725,7 +1725,8 @@ public final void onFailure(Exception e) {
17251725
ccsClusterInfoUpdate(f, clusters, clusterAlias, false);
17261726
}
17271727
Exception exception = e;
1728-
if (RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY.equals(clusterAlias) == false) {
1728+
if (RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY.equals(clusterAlias) == false
1729+
&& ExceptionsHelper.isTaskCancelledException(e) == false) {
17291730
exception = wrapRemoteClusterFailure(clusterAlias, e);
17301731
}
17311732
if (exceptions.compareAndSet(null, exception) == false) {

0 commit comments

Comments
 (0)