From 73d24203e7d260a9d0a12a0741b72a7b5840177c Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Fri, 13 Mar 2020 11:19:36 -0400 Subject: [PATCH] Handle no such remote cluster exception in ccr (#53415) A remote client can throw a NoSuchRemoteClusterException while fetching the cluster state from the leader cluster. We also need to handle that exception when retrying to add a retention lease to the leader shard. Closes #53225 --- .../ccr/action/ShardFollowTasksExecutor.java | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java index 12c56528ebe..54a614cd9d3 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java @@ -151,18 +151,9 @@ public class ShardFollowTasksExecutor extends PersistentTasksExecutor timeout = () -> isStopped() ? TimeValue.MINUS_ONE : waitForMetadataTimeOut; - - final Client remoteClient; - try { - remoteClient = remoteClient(params); - } catch (NoSuchRemoteClusterException e) { - errorHandler.accept(e); - return; - } - - CcrRequests.getIndexMetadata(remoteClient, leaderIndex, minRequiredMappingVersion, 0L, timeout, ActionListener.wrap( + final ActionListener listener = ActionListener.wrap( indexMetadata -> { - if (indexMetadata.getMappings().isEmpty()) { + if (indexMetadata.mapping() == null) { assert indexMetadata.getMappingVersion() == 1; handler.accept(indexMetadata.getMappingVersion()); return; @@ -176,7 +167,12 @@ public class ShardFollowTasksExecutor extends PersistentTasksExecutor wrappedListener = ActionListener.wrap( + r -> {}, + inner -> { + /* + * If this fails that the retention lease already exists, something highly unusual is + * going on. Log it, and renew again after another renew interval has passed. + */ + final Throwable innerCause = ExceptionsHelper.unwrapCause(inner); + logRetentionLeaseFailure(retentionLeaseId, innerCause); + }); + CcrRetentionLeases.asyncAddRetentionLease( params.getLeaderShardId(), retentionLeaseId, followerGlobalCheckpoint.getAsLong(), remoteClient(params), - ActionListener.wrap( - r -> {}, - inner -> { - /* - * If this fails that the retention lease already exists, something highly unusual is - * going on. Log it, and renew again after another renew interval has passed. - */ - final Throwable innerCause = ExceptionsHelper.unwrapCause(inner); - logRetentionLeaseFailure(retentionLeaseId, innerCause); - })); + wrappedListener); + } catch (NoSuchRemoteClusterException rce) { + // we will attempt to renew again after another renew interval has passed + logRetentionLeaseFailure(retentionLeaseId, rce); + } } else { // if something else happened, we will attempt to renew again after another renew interval has passed }