From 1899f36a967924e6c6de164becba74b2eedd3cc9 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Fri, 17 May 2024 09:18:43 -0700 Subject: [PATCH] handle exceptions individually --- .../action/fieldcaps/RequestDispatcher.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/RequestDispatcher.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/RequestDispatcher.java index fa093d771549..cf5b046da1ae 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/RequestDispatcher.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/RequestDispatcher.java @@ -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 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 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; } }