Skip to content

Commit

Permalink
Handle no such remote cluster exception in ccr (#53415)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dnhatn committed Apr 4, 2020
1 parent 0139e7c commit 9358784
Showing 1 changed file with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,9 @@ protected void innerUpdateMapping(long minRequiredMappingVersion, LongConsumer h
final Index followerIndex = params.getFollowShardId().getIndex();
final Index leaderIndex = params.getLeaderShardId().getIndex();
final Supplier<TimeValue> 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<IndexMetaData> listener = ActionListener.wrap(
indexMetaData -> {
if (indexMetaData.getMappings().isEmpty()) {
if (indexMetaData.mapping() == null) {
assert indexMetaData.getMappingVersion() == 1;
handler.accept(indexMetaData.getMappingVersion());
return;
Expand All @@ -176,7 +167,12 @@ protected void innerUpdateMapping(long minRequiredMappingVersion, LongConsumer h
errorHandler));
},
errorHandler
));
);
try {
CcrRequests.getIndexMetadata(remoteClient(params), leaderIndex, minRequiredMappingVersion, 0L, timeout, listener);
} catch (NoSuchRemoteClusterException e) {
errorHandler.accept(e);
}
}

@Override
Expand Down Expand Up @@ -445,21 +441,27 @@ protected Scheduler.Cancellable scheduleBackgroundRetentionLeaseRenewal(final Lo
"{} background adding retention lease [{}] while following",
params.getFollowShardId(),
retentionLeaseId);
CcrRetentionLeases.asyncAddRetentionLease(
try {
final ActionListener<RetentionLeaseActions.Response> 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
}
Expand Down

0 comments on commit 9358784

Please sign in to comment.