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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1485831 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-05-23 19:17:46 +00:00
parent 5876b39115
commit 6edd7326fd
5 changed files with 79 additions and 1 deletions

View File

@ -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
----------------------

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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>();