Skip to content

Commit

Permalink
[7.17] Handle failure in TransportUpdateAction#handleUpdateFailureWit…
Browse files Browse the repository at this point in the history
…hRetry (#97290) (#97326)

* Handle failure in TransportUpdateAction#handleUpdateFailureWithRetry (#97290)

Here executor(request.getShardId()) may throw, but we're already handling a failure so we cannot simply let this exception bubble up. This commit adjusts things to catch the exception, using it to fail the listener.

Closes #97286

* Fix

---------

Co-authored-by: Iraklis Psaroudakis <kingherc@gmail.com>
  • Loading branch information
DaveCTurner and kingherc authored Jul 3, 2023
1 parent 3bdd3fc commit 4ccdcce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/97290.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 97290
summary: Handle failure in `TransportUpdateAction#handleUpdateFailureWithRetry`
area: CRUD
type: bug
issues:
- 97286
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ExecutorService;

import static org.elasticsearch.ExceptionsHelper.unwrapCause;
import static org.elasticsearch.action.bulk.TransportSingleItemBulkWriteAction.toSingleItemBulkRequest;
Expand Down Expand Up @@ -325,20 +326,28 @@ private void handleUpdateFailureWithRetry(
int retryCount
) {
final Throwable cause = unwrapCause(failure);
if (cause instanceof VersionConflictEngineException) {
if (retryCount < request.retryOnConflict()) {
logger.trace(
"Retry attempt [{}] of [{}] on version conflict on [{}][{}][{}]",
retryCount + 1,
request.retryOnConflict(),
request.index(),
request.getShardId(),
request.id()
);
threadPool.executor(executor(request.getShardId()))
.execute(ActionRunnable.wrap(listener, l -> shardOperation(request, l, retryCount + 1)));
if (cause instanceof VersionConflictEngineException && retryCount < request.retryOnConflict()) {
VersionConflictEngineException versionConflictEngineException = (VersionConflictEngineException) cause;
logger.trace(
"Retry attempt [{}] of [{}] on version conflict on [{}][{}][{}]",
retryCount + 1,
request.retryOnConflict(),
request.index(),
request.getShardId(),
request.id()
);

final ExecutorService executor;
try {
executor = threadPool.executor(executor(request.getShardId()));
} catch (Exception e) {
// might fail if shard no longer exists locally, in which case we cannot retry
e.addSuppressed(versionConflictEngineException);
listener.onFailure(e);
return;
}
executor.execute(ActionRunnable.wrap(listener, l -> shardOperation(request, l, retryCount + 1)));
return;
}
listener.onFailure(cause instanceof Exception ? (Exception) cause : new NotSerializableExceptionWrapper(cause));
}
Expand Down

0 comments on commit 4ccdcce

Please sign in to comment.