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.

This commit is contained in:
Shalin Shekhar Mangar 2018-09-25 12:14:16 +05:30
parent 9bc4b8d4fe
commit e437b2f1ed
2 changed files with 9 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -332,7 +333,8 @@ public class Assign {
if (createNodeSet instanceof List) { if (createNodeSet instanceof List) {
createNodeList = (List) createNodeSet; createNodeList = (List) createNodeSet;
} else { } 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); HashMap<String, ReplicaCount> nodeNameVsShardCount = getNodeNameVsShardCount(collectionName, clusterState, createNodeList);

View File

@ -17,10 +17,9 @@
package org.apache.solr.cloud; package org.apache.solr.cloud;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet; 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.impl.CloudSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest; 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 // but adding any number of replicas is supported if an explicit create node set is specified
// so test that as well // so test that as well
List<String> createNodeSet = new ArrayList<>(2); LinkedHashSet<String> createNodeSet = new LinkedHashSet<>(2);
createNodeSet.add(cluster.getRandomJetty(random()).getNodeName());
createNodeSet.add(cluster.getRandomJetty(random()).getNodeName()); createNodeSet.add(cluster.getRandomJetty(random()).getNodeName());
while (true) {
String nodeName = cluster.getRandomJetty(random()).getNodeName();
if (createNodeSet.add(nodeName)) break;
}
addReplica = CollectionAdminRequest.addReplicaToShard(collection, "shard1") addReplica = CollectionAdminRequest.addReplicaToShard(collection, "shard1")
.setNrtReplicas(3) .setNrtReplicas(3)
.setTlogReplicas(1) .setTlogReplicas(1)