Skip to content

Apache Lucene open-source search software

SOLR-4814: If a SolrCore cannot be created it should remove any information it published about itself from ZooKeeper.

Mark Robert Miller6edd7326fdd6
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 9167d5d118a..27948e986f7 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -105,6 +105,9 @@ Bug Fixes
* SOLR-4842: Fix facet.field local params from affecting other facet.field's.
(ehatcher, hossman)
+* SOLR-4814: If a SolrCore cannot be created it should remove any information it
+ published about itself from ZooKeeper. (Mark Miller)
+
Other Changes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/Overseer.java b/solr/core/src/java/org/apache/solr/cloud/Overseer.java
index e2991f9d8a7..c5a9fb43a6c 100644
--- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java
+++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java
@@ -537,6 +537,15 @@ public class Overseer {
DocCollection coll = newCollections.get(collection);
if (coll == null) {
// TODO: log/error that we didn't find it?
+ // just in case, remove the zk collection node
+ try {
+ zkClient.clean("/collections/" + collection);
+ } catch (InterruptedException e) {
+ SolrException.log(log, "Cleaning up collection in zk was interrupted:" + collection, e);
+ Thread.currentThread().interrupt();
+ } catch (KeeperException e) {
+ SolrException.log(log, "Problem cleaning up collection in zk:" + collection, e);
+ }
return clusterState;
}
diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
index 89a74cb18ab..8ed9b1cde06 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -426,6 +426,16 @@ public class CoreContainer
c = create(p);
registerCore(p.isTransient(), name, c, false);
} catch (Throwable t) {
+ if (isZooKeeperAware()) {
+ try {
+ zkSys.zkController.unregister(name, p);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ SolrException.log(log, null, e);
+ } catch (KeeperException e) {
+ SolrException.log(log, null, e);
+ }
+ }
SolrException.log(log, null, t);
if (c != null) {
c.close();
@@ -988,6 +998,19 @@ public class CoreContainer
core.open();
}
} catch(Exception ex){
+ // remains to be seen how transient cores and such
+ // will work in SolrCloud mode, but just to be future
+ // proof...
+ if (isZooKeeperAware()) {
+ try {
+ getZkController().unregister(name, desc);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ SolrException.log(log, null, e);
+ } catch (KeeperException e) {
+ SolrException.log(log, null, e);
+ }
+ }
throw recordAndThrow(name, "Unable to create core: " + name, ex);
} finally {
solrCores.removeFromPendingOps(name);
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
index f089141cd55..97dfa106b0d 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
@@ -414,6 +414,7 @@ public class CoreAdminHandler extends RequestHandlerBase {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Core name is mandatory to CREATE a SolrCore");
}
+ CoreDescriptor dcore = null;
try {
if (coreContainer.getAllCoreNames().contains(name)) {
@@ -428,7 +429,7 @@ public class CoreAdminHandler extends RequestHandlerBase {
instanceDir = name; // bare name is already relative to solr home
}
- CoreDescriptor dcore = new CoreDescriptor(coreContainer, name, instanceDir);
+ dcore = new CoreDescriptor(coreContainer, name, instanceDir);
// fillup optional parameters
String opts = params.get(CoreAdminParams.CONFIG);
@@ -511,6 +512,16 @@ public class CoreAdminHandler extends RequestHandlerBase {
rsp.add("core", core.getName());
return coreContainer.isPersistent();
} catch (Exception ex) {
+ if (coreContainer.isZooKeeperAware() && dcore != null) {
+ try {
+ coreContainer.getZkController().unregister(name, dcore);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ SolrException.log(log, null, e);
+ } catch (KeeperException e) {
+ SolrException.log(log, null, e);
+ }
+ }
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Error CREATEing SolrCore '" + name + "': " +
ex.getMessage(), ex);
diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
index e9e7ae63e36..76c61763b4d 100644
--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
@@ -333,12 +333,44 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
testUpdateProcessorsRunOnlyOnce("distrib-dup-test-chain-implicit");
testStopAndStartCoresInOneInstance();
+ testFailedCoreCreateCleansUp();
// Thread.sleep(10000000000L);
if (DEBUG) {
super.printLayout();
}
}
+ private void testFailedCoreCreateCleansUp() throws Exception {
+ Create createCmd = new Create();
+ createCmd.setCoreName("core1");
+ createCmd.setCollection("the_core_collection");
+ String coredataDir = dataDir.getAbsolutePath() + File.separator
+ + System.currentTimeMillis() + "the_core_collection";
+ createCmd.setDataDir(coredataDir);
+ createCmd.setNumShards(1);
+ createCmd.setSchemaName("nonexistent_schema.xml");
+
+ String url = getBaseUrl(clients.get(0));
+ final HttpSolrServer server = new HttpSolrServer(url);
+ try {
+ server.request(createCmd);
+ fail("Expected SolrCore create to fail");
+ } catch (Exception e) {
+
+ }
+
+ long timeout = System.currentTimeMillis() + 15000;
+ while (cloudClient.getZkStateReader().getZkClient().exists("/collections/the_core_collection", true)) {
+ if (timeout <= System.currentTimeMillis()) {
+ fail(cloudClient.getZkStateReader().getZkClient().getChildren("/collections", null, true).toString() + " Collection zk node still exists");
+ }
+ Thread.sleep(100);
+ }
+
+
+ assertFalse("Collection zk node still exists", cloudClient.getZkStateReader().getZkClient().exists("/collections/the_core_collection", true));
+ }
+
private void testShardParamVariations() throws Exception {
SolrQuery query = new SolrQuery("*:*");
Map<String,Long> shardCounts = new HashMap<String,Long>();