Skip to content

Commit 9ef9621

Browse files
committed
Use cleanupOnly listener instead
1 parent 64cce51 commit 9ef9621

File tree

1 file changed

+17
-37
lines changed

1 file changed

+17
-37
lines changed

server/src/main/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetService.java

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -333,43 +333,23 @@ public void onFailure(Exception e) {
333333
if (indexShard.routingEntry().isSearchable() == false && recoveryState.getPrimary()) {
334334
assert preExistingRequest == null;
335335
assert indexShard.indexSettings().getIndexMetadata().isSearchableSnapshot() == false;
336-
try (onCompletion) {
337-
client.execute(
338-
StatelessPrimaryRelocationAction.TYPE,
339-
new StatelessPrimaryRelocationAction.Request(
340-
recoveryId,
341-
indexShard.shardId(),
342-
transportService.getLocalNode(),
343-
indexShard.routingEntry().allocationId().getId(),
344-
recoveryTarget.clusterStateVersion()
345-
),
346-
new ActionListener<>() {
347-
@Override
348-
public void onResponse(ActionResponse.Empty ignored) {
349-
onGoingRecoveries.markRecoveryAsDone(recoveryId);
350-
}
351-
352-
@Override
353-
public void onFailure(Exception e) {
354-
final var cause = ExceptionsHelper.unwrapCause(e);
355-
final var sendShardFailure =
356-
// these indicate the source shard has already failed, which will independently notify the master and fail
357-
// the target shard
358-
false == (cause instanceof ShardNotFoundException
359-
|| cause instanceof IndexNotFoundException
360-
|| cause instanceof AlreadyClosedException);
361-
362-
// TODO retries? See RecoveryResponseHandler#handleException
363-
onGoingRecoveries.failRecovery(
364-
recoveryId,
365-
new RecoveryFailedException(recoveryState, null, e),
366-
sendShardFailure
367-
);
368-
}
369-
}
370-
);
371-
return;
372-
}
336+
client.execute(
337+
StatelessPrimaryRelocationAction.TYPE,
338+
new StatelessPrimaryRelocationAction.Request(
339+
recoveryId,
340+
indexShard.shardId(),
341+
transportService.getLocalNode(),
342+
indexShard.routingEntry().allocationId().getId(),
343+
recoveryTarget.clusterStateVersion()
344+
),
345+
cleanupOnly.delegateFailure((l, unused) -> {
346+
ActionListener.completeWith(l, () -> {
347+
onGoingRecoveries.markRecoveryAsDone(recoveryId);
348+
return null;
349+
});
350+
})
351+
);
352+
return;
373353
}
374354

375355
record StartRecoveryRequestToSend(StartRecoveryRequest startRecoveryRequest, String actionName, TransportRequest requestToSend) {}

0 commit comments

Comments
 (0)