Apache Solr open-source search software
SOLR-4601: A Collection that is only partially created and then deleted will leave pre allocated shard information in ZooKeeper.
Mark Robert Millerc12d7e22f1c5
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 36565e4df2d..3c663da435a 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -157,6 +157,9 @@ Bug Fixes* SOLR-4602: ZkController#unregister should cancel it's election participationbefore 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----------------------diff --git a/solr/core/src/java/org/apache/solr/cloud/Overseer.java b/solr/core/src/java/org/apache/solr/cloud/Overseer.javaindex 9ee80a0bad9..9e482bedf2e 100644--- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java+++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java@@ -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 itif (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) {diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.javaindex fc9ddc4c017..c32019bf6ac 100644--- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java@@ -361,7 +361,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {+ 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 implements Runnable, ClosableThread {}}- 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 implements Runnable, ClosableThread {}}- int failed = 0;ShardResponse srsp;do {srsp = shardHandler.takeCompletedOrError();@@ -483,12 +482,6 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {}} while (srsp != null);-- // if all calls succeeded, return true- if (failed > 0) {- return false;- }- return true;}private void processResponse(NamedList results, ShardResponse srsp) {diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.javaindex 3f8f41a6b30..2fbbdda7b7b 100644--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java@@ -141,15 +141,57 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa@Overridepublic 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 CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBaparams.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 CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa// leave out required param nameparams = new ModifiableSolrParams();params.set("action", CollectionAction.CREATE.toString());+ params.set("numShards", 2);collectionName = "collection";// No Name// params.set("name", collectionName);