Skip to content

Commit 375a211

Browse files
authored
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
1 parent 1fc3fe3 commit 375a211

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java

+24-22
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,7 @@ protected void innerUpdateMapping(long minRequiredMappingVersion, LongConsumer h
132132
final Index followerIndex = params.getFollowShardId().getIndex();
133133
final Index leaderIndex = params.getLeaderShardId().getIndex();
134134
final Supplier<TimeValue> timeout = () -> isStopped() ? TimeValue.MINUS_ONE : waitForMetadataTimeOut;
135-
136-
final Client remoteClient;
137-
try {
138-
remoteClient = remoteClient(params);
139-
} catch (NoSuchRemoteClusterException e) {
140-
errorHandler.accept(e);
141-
return;
142-
}
143-
144-
CcrRequests.getIndexMetadata(remoteClient, leaderIndex, minRequiredMappingVersion, 0L, timeout, ActionListener.wrap(
135+
final ActionListener<IndexMetaData> listener = ActionListener.wrap(
145136
indexMetaData -> {
146137
if (indexMetaData.mapping() == null) {
147138
assert indexMetaData.getMappingVersion() == 1;
@@ -155,7 +146,12 @@ protected void innerUpdateMapping(long minRequiredMappingVersion, LongConsumer h
155146
errorHandler));
156147
},
157148
errorHandler
158-
));
149+
);
150+
try {
151+
CcrRequests.getIndexMetadata(remoteClient(params), leaderIndex, minRequiredMappingVersion, 0L, timeout, listener);
152+
} catch (NoSuchRemoteClusterException e) {
153+
errorHandler.accept(e);
154+
}
159155
}
160156

161157
@Override
@@ -424,21 +420,27 @@ protected Scheduler.Cancellable scheduleBackgroundRetentionLeaseRenewal(final Lo
424420
"{} background adding retention lease [{}] while following",
425421
params.getFollowShardId(),
426422
retentionLeaseId);
427-
CcrRetentionLeases.asyncAddRetentionLease(
423+
try {
424+
final ActionListener<RetentionLeaseActions.Response> wrappedListener = ActionListener.wrap(
425+
r -> {},
426+
inner -> {
427+
/*
428+
* If this fails that the retention lease already exists, something highly unusual is
429+
* going on. Log it, and renew again after another renew interval has passed.
430+
*/
431+
final Throwable innerCause = ExceptionsHelper.unwrapCause(inner);
432+
logRetentionLeaseFailure(retentionLeaseId, innerCause);
433+
});
434+
CcrRetentionLeases.asyncAddRetentionLease(
428435
params.getLeaderShardId(),
429436
retentionLeaseId,
430437
followerGlobalCheckpoint.getAsLong(),
431438
remoteClient(params),
432-
ActionListener.wrap(
433-
r -> {},
434-
inner -> {
435-
/*
436-
* If this fails that the retention lease already exists, something highly unusual is
437-
* going on. Log it, and renew again after another renew interval has passed.
438-
*/
439-
final Throwable innerCause = ExceptionsHelper.unwrapCause(inner);
440-
logRetentionLeaseFailure(retentionLeaseId, innerCause);
441-
}));
439+
wrappedListener);
440+
} catch (NoSuchRemoteClusterException rce) {
441+
// we will attempt to renew again after another renew interval has passed
442+
logRetentionLeaseFailure(retentionLeaseId, rce);
443+
}
442444
} else {
443445
// if something else happened, we will attempt to renew again after another renew interval has passed
444446
}

0 commit comments

Comments
 (0)