You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2012/11/20 06:08:08 UTC

svn commit: r1411536 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java

Author: markrmiller
Date: Tue Nov 20 05:08:07 2012
New Revision: 1411536

URL: http://svn.apache.org/viewvc?rev=1411536&view=rev
Log:
SOLR-4034: Check if a collection already exists before trying to create a new one.

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1411536&r1=1411535&r2=1411536&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Tue Nov 20 05:08:07 2012
@@ -226,6 +226,9 @@ Bug Fixes
   
 * SOLR-4075: A logical shard that has had all of it's SolrCores unloaded should 
   be removed from the cluster state. (Mark Miller, Gilles Comeau)
+  
+* SOLR-4034: Check if a collection already exists before trying to create a
+  new one. (Po Rui, Mark Miller)
 
 Other Changes
 ----------------------

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java?rev=1411536&r1=1411535&r2=1411536&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java Tue Nov 20 05:08:07 2012
@@ -158,7 +158,12 @@ public class OverseerCollectionProcessor
   }
 
   private boolean createCollection(ClusterState clusterState, ZkNodeProps message) {
-    
+	  String collectionName = message.getStr("name");
+	  if(clusterState.getCollections().contains(collectionName)) {
+	    SolrException.log(log, "collection already exists: " + collectionName);
+		  return false;
+	  }
+	  
     // look at the replication factor and see if it matches reality
     // if it does not, find best nodes to create more cores
     
@@ -179,6 +184,17 @@ public class OverseerCollectionProcessor
       return false;
     }
     
+    if (numReplicas < 0) {
+      SolrException.log(log, REPLICATION_FACTOR + " must be > 0");
+      return false;
+    }
+    
+    if (numShards < 0) {
+      SolrException.log(log, "numShards must be > 0");
+      return false;
+    }
+    
+    
     String name = message.getStr("name");
     String configName = message.getStr("collection.configName");
     
@@ -198,6 +214,14 @@ public class OverseerCollectionProcessor
     Collections.shuffle(nodeList);
     
     int numNodes = numShards * (numReplicas + 1);
+    if (nodeList.size() < numNodes) {
+      log.warn("Not enough nodes available to satisfy create collection request for collection:"
+                  + collectionName
+                  + " nodes needed:"
+                  + numNodes
+                  + " nodes available:" + nodeList.size() + " - using nodes available");
+    }
+
     List<String> createOnNodes = nodeList.subList(0, Math.min(nodeList.size(), numNodes));
     
     log.info("Create collection " + name + " on " + createOnNodes);

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java?rev=1411536&r1=1411535&r2=1411536&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java Tue Nov 20 05:08:07 2012
@@ -739,7 +739,7 @@ public class BasicDistributedZkTest exte
     for (int i = 0; i < cnt; i++) {
       createCollection(collectionInfos, i,
           _TestUtil.nextInt(random(), 0, shardCount) + 1,
-          _TestUtil.nextInt(random(), 0, 5) + 1);
+          _TestUtil.nextInt(random(), 0, 3) + 1);
     }
     
     Set<Entry<String,List<Integer>>> collectionInfosEntrySet = collectionInfos.entrySet();