From 5c4ffc8a8cd880bfeefc8590f06e539c3ab1ff45 Mon Sep 17 00:00:00 2001 From: SivagurunathanV Date: Thu, 24 Jan 2019 08:00:46 -0600 Subject: [PATCH 1/2] Fix for #37739 --- .../rest/src/main/java/org/elasticsearch/client/RestClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java index 3b1946ef9ed58..c587e71973f65 100644 --- a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java +++ b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java @@ -398,7 +398,7 @@ static Iterable selectNodes(NodeTuple> nodeTuple, Map livingNodes = new ArrayList<>(nodeTuple.nodes.size() - blacklist.size()); + List livingNodes = new ArrayList<>(Math.max(0,nodeTuple.nodes.size() - blacklist.size())); List deadNodes = new ArrayList<>(blacklist.size()); for (Node node : nodeTuple.nodes) { DeadHostState deadness = blacklist.get(node.getHost()); From b5625fd2bb786829266ae11ccf241fd2281c63ac Mon Sep 17 00:00:00 2001 From: Sivagurunathan Velayutham Date: Thu, 24 Jan 2019 19:40:13 -0600 Subject: [PATCH 2/2] Adding Test Case --- .../main/java/org/elasticsearch/client/RestClient.java | 2 +- .../java/org/elasticsearch/client/RestClientTests.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java index c587e71973f65..d053bda7d44fa 100644 --- a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java +++ b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java @@ -398,7 +398,7 @@ static Iterable selectNodes(NodeTuple> nodeTuple, Map livingNodes = new ArrayList<>(Math.max(0,nodeTuple.nodes.size() - blacklist.size())); + List livingNodes = new ArrayList<>(Math.max(0, nodeTuple.nodes.size() - blacklist.size())); List deadNodes = new ArrayList<>(blacklist.size()); for (Node node : nodeTuple.nodes) { DeadHostState deadness = blacklist.get(node.getHost()); diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java index 69cdfeae85dff..f3f0f0e58b98d 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java @@ -272,6 +272,15 @@ public String toString() { blacklist.put(n2.getHost(), new DeadHostState(new DeadHostState(timeSupplier))); blacklist.put(n3.getHost(), new DeadHostState(new DeadHostState(new DeadHostState(timeSupplier)))); + /* + * case when fewer nodeTuple than blacklist, wont result in any IllegalCapacityException + */ + { + NodeTuple> fewerNodeTuple = new NodeTuple<>(Arrays.asList(n1, n2), null); + assertSelectLivingHosts(Arrays.asList(n1), fewerNodeTuple, blacklist, NodeSelector.ANY); + assertSelectLivingHosts(Arrays.asList(n2), fewerNodeTuple, blacklist, not1); + } + /* * selectHosts will revive a single host if regardless of * blacklist time. It'll revive the node that is closest