Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Brooks committed Jul 20, 2023
1 parent 1a76a94 commit 07df954
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,42 @@ private void iterateBeforeIndexShardRecovery(
outerListener.onResponse(null);
}

private void iterateAfterIndexShardRecovery(
final IndexShard indexShard,
final Iterator<IndexEventListener> iterator,
final ActionListener<Void> outerListener
) {
while (iterator.hasNext()) {
final var nextListener = iterator.next();
final var future = new ListenableFuture<Void>();
try {
nextListener.afterIndexShardRecovery(indexShard, future);
if (future.isDone()) {
// common case, not actually async, so just check for an exception and continue on the same thread
future.result();
continue;
}
} catch (Exception e) {
outerListener.onFailure(e);
return;
}

// future was not completed straight away, but might be done by now, so continue on a fresh thread to avoid stack overflow
future.addListener(
outerListener.delegateFailure(
(delegate, v) -> indexShard.getThreadPool()
.executor(ThreadPool.Names.GENERIC)
.execute(
ActionRunnable.wrap(delegate, l -> iterateAfterIndexShardRecovery(indexShard, iterator, l))
)
)
);
return;
}

outerListener.onResponse(null);
}

@Override
public void beforeIndexShardRecovery(
final IndexShard indexShard,
Expand All @@ -292,6 +328,14 @@ public void beforeIndexShardRecovery(
}));
}

@Override
public void afterIndexShardRecovery(IndexShard indexShard, ActionListener<Void> outerListener) {
iterateAfterIndexShardRecovery(indexShard, listeners.iterator(), outerListener.delegateResponse((l, e) -> {
logger.warn(() -> format("failed to invoke the listener after the shard recovery for %s", indexShard.shardId()), e);
l.onFailure(e);
}));
}

@Override
public void afterFilesRestoredFromRepository(IndexShard indexShard) {
for (IndexEventListener listener : listeners) {
Expand Down

0 comments on commit 07df954

Please sign in to comment.