From e437b2f1ed80af6bb8b909f64511fe43829eb67d Mon Sep 17 00:00:00 2001
From: Shalin Shekhar Mangar <shalin@apache.org>
Date: Tue, 25 Sep 2018 12:14:16 +0530
Subject: [PATCH] SOLR-9317: Deduplicate node list before trying to find if all
 nodes are up. The test is also fixed to not send duplicate node names in the
 createNodeSet parameter.

---
 .../org/apache/solr/cloud/api/collections/Assign.java  |  4 +++-
 .../src/test/org/apache/solr/cloud/AddReplicaTest.java | 10 ++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java
index 42de84a8628..9b33f521862 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -332,7 +333,8 @@ public class Assign {
     if (createNodeSet instanceof List) {
       createNodeList = (List) createNodeSet;
     } else {
-      createNodeList = createNodeSet == null ? null : StrUtils.splitSmart((String) createNodeSet, ",", true);
+      // deduplicate
+      createNodeList = createNodeSet == null ? null : new ArrayList<>(new LinkedHashSet<>(StrUtils.splitSmart((String) createNodeSet, ",", true)));
     }
 
      HashMap<String, ReplicaCount> nodeNameVsShardCount = getNodeNameVsShardCount(collectionName, clusterState, createNodeList);
diff --git a/solr/core/src/test/org/apache/solr/cloud/AddReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/AddReplicaTest.java
index 342a27d2f79..8980ba8ccdb 100644
--- a/solr/core/src/test/org/apache/solr/cloud/AddReplicaTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/AddReplicaTest.java
@@ -17,10 +17,9 @@
 package org.apache.solr.cloud;
 
 import java.lang.invoke.MethodHandles;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.EnumSet;
-import java.util.List;
+import java.util.LinkedHashSet;
 
 import org.apache.solr.client.solrj.impl.CloudSolrClient;
 import org.apache.solr.client.solrj.request.CollectionAdminRequest;
@@ -98,9 +97,12 @@ public class AddReplicaTest extends SolrCloudTestCase {
 
     // but adding any number of replicas is supported if an explicit create node set is specified
     // so test that as well
-    List<String> createNodeSet = new ArrayList<>(2);
-    createNodeSet.add(cluster.getRandomJetty(random()).getNodeName());
+    LinkedHashSet<String> createNodeSet = new LinkedHashSet<>(2);
     createNodeSet.add(cluster.getRandomJetty(random()).getNodeName());
+    while (true)  {
+      String nodeName = cluster.getRandomJetty(random()).getNodeName();
+      if (createNodeSet.add(nodeName))  break;
+    }
     addReplica = CollectionAdminRequest.addReplicaToShard(collection, "shard1")
         .setNrtReplicas(3)
         .setTlogReplicas(1)