Skip to content

Commit

Permalink
handle exceptions individually
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed May 17, 2024
1 parent 85d6862 commit 1899f36
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,24 @@ final class RequestDispatcher {
this.onIndexFailure = onIndexFailure;
this.onComplete = new RunOnce(onComplete);
this.indexSelectors = ConcurrentCollections.newConcurrentMap();
try {
for (String index : indices) {
final GroupShardsIterator<ShardIterator> shardIts = clusterService.operationRouting()
.searchShards(clusterState, new String[] { index }, null, null, null, null);
final IndexSelector indexResult = new IndexSelector(shardIts);
if (indexResult.nodeToShards.isEmpty()) {
onIndexFailure.accept(
index,
new NoShardAvailableActionException(null, "index [" + index + "] has no active shard copy")
);
} else {
this.indexSelectors.put(index, indexResult);
}
for (String index : indices) {
final GroupShardsIterator<ShardIterator> shardIts;
try {
shardIts = clusterService.operationRouting()
.searchShards(clusterState, new String[]{index}, null, null, null, null);
} catch (Exception e) {
onIndexFailure.accept(index, e);
continue;
}
final IndexSelector indexResult = new IndexSelector(shardIts);
if (indexResult.nodeToShards.isEmpty()) {
onIndexFailure.accept(
index,
new NoShardAvailableActionException(null, "index [" + index + "] has no active shard copy")
);
} else {
this.indexSelectors.put(index, indexResult);
}
} catch (Exception e) {
this.onComplete.run();
throw e;
}
}

Expand Down

0 comments on commit 1899f36

Please sign in to comment.