You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2017/08/03 02:17:05 UTC

lucene-solr:branch_7x: SOLR-11011: Fix AssignTest.testIdIsUnique() failure

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 0f1b55985 -> b4d91fa23


SOLR-11011: Fix AssignTest.testIdIsUnique() failure


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b4d91fa2
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b4d91fa2
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b4d91fa2

Branch: refs/heads/branch_7x
Commit: b4d91fa238c40e942e85fee25dc7a91794bfbf54
Parents: 0f1b559
Author: Cao Manh Dat <da...@apache.org>
Authored: Thu Aug 3 09:16:10 2017 +0700
Committer: Cao Manh Dat <da...@apache.org>
Committed: Thu Aug 3 09:16:54 2017 +0700

----------------------------------------------------------------------
 .../src/java/org/apache/solr/cloud/Assign.java  | 30 +++++++++++++++-----
 .../apache/solr/cloud/CreateCollectionCmd.java  |  2 +-
 .../org/apache/solr/cloud/OverseerTest.java     |  4 +++
 3 files changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b4d91fa2/solr/core/src/java/org/apache/solr/cloud/Assign.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/Assign.java b/solr/core/src/java/org/apache/solr/cloud/Assign.java
index 98dcfde..116fce9 100644
--- a/solr/core/src/java/org/apache/solr/cloud/Assign.java
+++ b/solr/core/src/java/org/apache/solr/cloud/Assign.java
@@ -115,12 +115,12 @@ public class Assign {
 
   public static String assignNode(SolrZkClient client, DocCollection collection) {
     // for backward compatibility;
-    int numReplicas = collection.getReplicas().size();
-    String coreNodeName = "core_node" + incAndGetId(client, collection.getName(), numReplicas * 20);
+    int defaultValue = defaultCounterValue(collection, false);
+    String coreNodeName = "core_node" + incAndGetId(client, collection.getName(), defaultValue);
     while (collection.getReplica(coreNodeName) != null) {
       // there is wee chance that, the new coreNodeName id not totally unique,
       // but this will be guaranteed unique for new collections
-      coreNodeName = "core_node" + incAndGetId(client, collection.getName(), numReplicas * 20);
+      coreNodeName = "core_node" + incAndGetId(client, collection.getName(), defaultValue);
     }
     return coreNodeName;
   }
@@ -174,18 +174,34 @@ public class Assign {
     return String.format(Locale.ROOT, "%s_%s_replica_%s%s", collectionName, shard, type.name().substring(0,1).toLowerCase(Locale.ROOT), replicaNum);
   }
 
-  public static String buildCoreName(SolrZkClient zkClient, DocCollection collection, String shard, Replica.Type type) {
+  private static int defaultCounterValue(DocCollection collection, boolean newCollection) {
+    if (newCollection) return 0;
+    int defaultValue = collection.getReplicas().size();
+    if (collection.getReplicationFactor() != null) {
+      // numReplicas and replicationFactor * numSlices can be not equals,
+      // in case of many addReplicas or deleteReplicas are executed
+      defaultValue = Math.max(defaultValue,
+          collection.getReplicationFactor() * collection.getSlices().size());
+    }
+    return defaultValue * 20;
+  }
+
+  public static String buildCoreName(SolrZkClient zkClient, DocCollection collection, String shard, Replica.Type type, boolean newCollection) {
     Slice slice = collection.getSlice(shard);
-    int numReplicas = collection.getReplicas().size();
-    int replicaNum = incAndGetId(zkClient, collection.getName(), numReplicas * 20);
+    int defaultValue = defaultCounterValue(collection, newCollection);
+    int replicaNum = incAndGetId(zkClient, collection.getName(), defaultValue);
     String coreName = buildCoreName(collection.getName(), shard, type, replicaNum);
     while (existCoreName(coreName, slice)) {
-      replicaNum = incAndGetId(zkClient, collection.getName(), numReplicas * 20);
+      replicaNum = incAndGetId(zkClient, collection.getName(), defaultValue);
       coreName = buildCoreName(collection.getName(), shard, type, replicaNum);
     }
     return coreName;
   }
 
+  public static String buildCoreName(SolrZkClient zkClient, DocCollection collection, String shard, Replica.Type type) {
+    return buildCoreName(zkClient, collection, shard, type, false);
+  }
+
   private static boolean existCoreName(String coreName, Slice slice) {
     if (slice == null) return false;
     for (Replica replica : slice.getReplicas()) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b4d91fa2/solr/core/src/java/org/apache/solr/cloud/CreateCollectionCmd.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/CreateCollectionCmd.java b/solr/core/src/java/org/apache/solr/cloud/CreateCollectionCmd.java
index 3a51ada..fc96a61 100644
--- a/solr/core/src/java/org/apache/solr/cloud/CreateCollectionCmd.java
+++ b/solr/core/src/java/org/apache/solr/cloud/CreateCollectionCmd.java
@@ -212,7 +212,7 @@ public class CreateCollectionCmd implements Cmd {
       for (ReplicaPosition replicaPosition : replicaPositions) {
         String nodeName = replicaPosition.node;
         String coreName = Assign.buildCoreName(ocmh.zkStateReader.getZkClient(), zkStateReader.getClusterState().getCollection(collectionName),
-            replicaPosition.shard, replicaPosition.type);
+            replicaPosition.shard, replicaPosition.type, true);
         log.debug(formatString("Creating core {0} as part of shard {1} of collection {2} on {3}"
             , coreName, replicaPosition.shard, collectionName, nodeName));
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b4d91fa2/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java
index 1fbf98c..b921e39 100644
--- a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java
@@ -441,6 +441,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
           ZkStateReader.COLLECTION_PROP, COLLECTION,
           ZkStateReader.SHARD_ID_PROP, "shard1",
           ZkStateReader.CORE_NAME_PROP, "core1",
+          ZkStateReader.CORE_NODE_NAME_PROP, "core_node1",
           ZkStateReader.ROLES_PROP, "",
           ZkStateReader.STATE_PROP, Replica.State.RECOVERING.toString());
       
@@ -1063,6 +1064,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
           ZkStateReader.NODE_NAME_PROP, "node1",
           ZkStateReader.COLLECTION_PROP, "c1",
           ZkStateReader.CORE_NAME_PROP, "core1",
+          ZkStateReader.CORE_NODE_NAME_PROP, "core_node1",
           ZkStateReader.ROLES_PROP, "",
           ZkStateReader.STATE_PROP, Replica.State.DOWN.toString());
 
@@ -1118,6 +1120,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
           "collection", "test",
           ZkStateReader.SHARD_ID_PROP, "x",
           ZkStateReader.BASE_URL_PROP, "http://127.0.0.1/solr",
+          ZkStateReader.CORE_NODE_NAME_PROP, "core_node1",
           ZkStateReader.NODE_NAME_PROP, "node1",
           ZkStateReader.CORE_NAME_PROP, "core1",
           ZkStateReader.STATE_PROP, Replica.State.DOWN.toString()
@@ -1231,6 +1234,7 @@ public class OverseerTest extends SolrTestCaseJ4 {
               ZkStateReader.NODE_NAME_PROP, "node"+N,
               ZkStateReader.COLLECTION_PROP, COLLECTION,
               ZkStateReader.CORE_NAME_PROP, "core"+N,
+              ZkStateReader.CORE_NODE_NAME_PROP, "core_node"+N,
               ZkStateReader.ROLES_PROP, "",
               ZkStateReader.STATE_PROP, Replica.State.RECOVERING.toString());