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 2013/03/18 00:18:02 UTC

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

Author: markrmiller
Date: Sun Mar 17 23:18:02 2013
New Revision: 1457585

URL: http://svn.apache.org/r1457585
Log:
SOLR-4601: A Collection that is only partially created and then deleted will leave pre allocated shard information in ZooKeeper.

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

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1457585&r1=1457584&r2=1457585&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Sun Mar 17 23:18:02 2013
@@ -157,6 +157,9 @@ Bug Fixes
 * SOLR-4602: ZkController#unregister should cancel it's election participation 
   before asking the Overseer to delete the SolrCore information. (Mark Miller)
 
+* SOLR-4601: A Collection that is only partially created and then deleted will 
+  leave pre allocated shard information in ZooKeeper. (Mark Miller)
+
 Optimizations
 ----------------------
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/Overseer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/Overseer.java?rev=1457585&r1=1457584&r2=1457585&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/Overseer.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/Overseer.java Sun Mar 17 23:18:02 2013
@@ -459,6 +459,7 @@ public class Overseer {
         }
 
         Map<String, Slice> newSlices = new LinkedHashMap<String, Slice>();
+        boolean lastSlice = false;
         for (Slice slice : coll.getSlices()) {
           Replica replica = slice.getReplica(cnn);
           if (replica != null) {
@@ -469,6 +470,7 @@ public class Overseer {
             // if there are no replicas left for the slice remove it
             if (newReplicas.size() == 0) {
               slice = null;
+              lastSlice = true;
             } else {
               slice = new Slice(slice.getName(), newReplicas, slice.getProperties());
             }
@@ -478,6 +480,15 @@ public class Overseer {
             newSlices.put(slice.getName(), slice);
           }
         }
+        
+        if (lastSlice) {
+          // remove all empty pre allocated slices
+          for (Slice slice : coll.getSlices()) {
+            if (slice.getReplicas().size() == 0) {
+              newSlices.remove(slice.getName());
+            }
+          }
+        }
 
         // if there are no slices left in the collection, remove it?
         if (newSlices.size() == 0) {

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=1457585&r1=1457584&r2=1457585&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 Sun Mar 17 23:18:02 2013
@@ -361,7 +361,7 @@ public class OverseerCollectionProcessor
             + repFactor
             + " on collection "
             + collectionName
-            + " is higher than or equal to the number of Solr instances currently live ("
+            + " is higher than or equal to the number of Solr instances currently live or part of your " + CREATE_NODE_SET + "("
             + nodeList.size()
             + "). Its unusual to run two replica of the same slice on the same Solr-instance.");
       }
@@ -432,7 +432,7 @@ public class OverseerCollectionProcessor
     }
   }
   
-  private boolean collectionCmd(ClusterState clusterState, ZkNodeProps message, ModifiableSolrParams params, NamedList results) {
+  private void collectionCmd(ClusterState clusterState, ZkNodeProps message, ModifiableSolrParams params, NamedList results) {
     log.info("Executing Collection Cmd : " + params);
     String collectionName = message.getStr("name");
     
@@ -474,7 +474,6 @@ public class OverseerCollectionProcessor
       }
     }
     
-    int failed = 0;
     ShardResponse srsp;
     do {
       srsp = shardHandler.takeCompletedOrError();
@@ -483,12 +482,6 @@ public class OverseerCollectionProcessor
       }
     } while (srsp != null);
 
-    
-    // if all calls succeeded, return true
-    if (failed > 0) {
-      return false;
-    }
-    return true;
   }
 
   private void processResponse(NamedList results, ShardResponse srsp) {

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java?rev=1457585&r1=1457584&r2=1457585&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java Sun Mar 17 23:18:02 2013
@@ -141,15 +141,57 @@ public class CollectionsAPIDistributedZk
   
   @Override
   public void doTest() throws Exception {
-
+    
     testNodesUsedByCreate();
     testCollectionsAPI();
+    deletePartiallyCreatedCollection();
     testErrorHandling();
 
     if (DEBUG) {
       super.printLayout();
     }
   }
+  
+  private void deletePartiallyCreatedCollection() throws Exception {
+    final String baseUrl = getBaseUrl((HttpSolrServer) clients.get(0));
+    String collectionName = "halfdeletedcollection";
+    Create createCmd = new Create();
+    createCmd.setCoreName("halfdeletedcollection_shard1_replica1");
+    createCmd.setCollection(collectionName);
+    String dataDir = SolrTestCaseJ4.dataDir.getAbsolutePath() + File.separator
+        + System.currentTimeMillis() + "halfcollection" + "_hdn";
+    createCmd.setDataDir(dataDir);
+    createCmd.setNumShards(2);
+    createNewSolrServer("", baseUrl).request(createCmd);
+    
+    printLayout();
+    
+
+    ModifiableSolrParams params = new ModifiableSolrParams();
+    params.set("action", CollectionAction.DELETE.toString());
+    params.set("name", collectionName);
+    QueryRequest request = new QueryRequest(params);
+    request.setPath("/admin/collections");
+
+    NamedList<Object> resp = createNewSolrServer("", baseUrl).request(request);
+    
+    
+    Thread.sleep(5000);
+    
+    printLayout();
+    
+    
+    // now creating that collection should work
+    // try a bad action
+    params = new ModifiableSolrParams();
+    params.set("action", CollectionAction.CREATE.toString());
+    params.set("name", collectionName);
+    params.set("numShards", 2);
+    request = new QueryRequest(params);
+    request.setPath("/admin/collections");
+    resp = createNewSolrServer("", baseUrl).request(request);
+
+  }
 
   private void testErrorHandling() throws Exception {
     final String baseUrl = getBaseUrl((HttpSolrServer) clients.get(0));
@@ -160,6 +202,7 @@ public class CollectionsAPIDistributedZk
     params.set("action", "BADACTION");
     String collectionName = "badactioncollection";
     params.set("name", collectionName);
+    params.set("numShards", 2);
     QueryRequest request = new QueryRequest(params);
     request.setPath("/admin/collections");
     boolean gotExp = false;
@@ -175,6 +218,7 @@ public class CollectionsAPIDistributedZk
     // leave out required param name
     params = new ModifiableSolrParams();
     params.set("action", CollectionAction.CREATE.toString());
+    params.set("numShards", 2);
     collectionName = "collection";
     // No Name
     // params.set("name", collectionName);