SOLR-2651: The new SolrCore#reload method does not create a ZkSolrResourceLoader in ZooKeeper mode

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1146905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2011-07-14 21:43:07 +00:00
parent 6556cedcbb
commit d0c71f9702
5 changed files with 67 additions and 17 deletions

View File

@ -206,7 +206,7 @@ Bug Fixes
* SOLR-2275: fix DisMax 'mm' parsing to be tolerant of whitespace
(Erick Erickson via hossman)
* SOLR-2193, SOLR-2565: SolrCores now properly share IndexWriters across SolrCore reloads.
* SOLR-2193, SOLR-2565, SOLR-2651: SolrCores now properly share IndexWriters across SolrCore reloads.
(Mark Miller, Robert Muir)
* SOLR-2535: REGRESSION: in Solr 3.x and trunk the admin/file handler

View File

@ -39,7 +39,6 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.ZooKeeperException;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.util.DOMUtil;
import org.apache.solr.common.util.XML;
import org.apache.solr.common.util.FileUtils;
import org.apache.solr.common.util.SystemIdResolver;
import org.apache.solr.core.SolrXMLSerializer.SolrCoreXMLDef;
@ -713,7 +712,42 @@ public class CoreContainer
if (core == null)
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "No such core: " + name );
SolrCore newCore = core.reload(libLoader);
CoreDescriptor cd = core.getCoreDescriptor();
File instanceDir = new File(cd.getInstanceDir());
if (!instanceDir.isAbsolute()) {
instanceDir = new File(getSolrHome(), instanceDir.getName());
}
SolrResourceLoader solrLoader;
if(zkController == null) {
solrLoader = new SolrResourceLoader(instanceDir.getAbsolutePath(), libLoader, getCoreProps(instanceDir.getAbsolutePath(), cd.getPropertiesName(),cd.getCoreProperties()));
} else {
try {
String collection = cd.getCloudDescriptor().getCollectionName();
zkController.createCollectionZkNode(cd.getCloudDescriptor());
String zkConfigName = zkController.readConfigName(collection);
if (zkConfigName == null) {
log.error("Could not find config name for collection:" + collection);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"Could not find config name for collection:" + collection);
}
solrLoader = new ZkSolrResourceLoader(instanceDir.getAbsolutePath(), zkConfigName, libLoader, getCoreProps(instanceDir.getAbsolutePath(), cd.getPropertiesName(),cd.getCoreProperties()), zkController);
} catch (KeeperException e) {
log.error("", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);
} catch (InterruptedException e) {
// Restore the interrupted status
Thread.currentThread().interrupt();
log.error("", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"", e);
}
}
SolrCore newCore = core.reload(solrLoader);
register(name, newCore, false);
}

View File

@ -20,7 +20,6 @@ package org.apache.solr.core;
import org.apache.lucene.index.IndexDeletionPolicy;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.codecs.Codec;
import org.apache.lucene.index.codecs.CodecProvider;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.store.Directory;
@ -297,20 +296,18 @@ public final class SolrCore implements SolrInfoMBean {
responseWriters.put(name, responseWriter);
}
public SolrCore reload(ClassLoader libLoader) throws IOException, ParserConfigurationException, SAXException {
// TODO - null descriptor and what if indexwriter settings have changed
SolrResourceLoader solrLoader = new SolrResourceLoader(getResourceLoader()
.getInstanceDir(), libLoader, CoreContainer.getCoreProps(
getResourceLoader().getInstanceDir(),
coreDescriptor.getPropertiesName(), coreDescriptor.getCoreProperties()));
SolrConfig config = new SolrConfig(solrLoader,
coreDescriptor.getConfigName(), null);
public SolrCore reload(SolrResourceLoader resourceLoader) throws IOException,
ParserConfigurationException, SAXException {
// TODO - what if indexwriter settings have changed
SolrConfig config = new SolrConfig(resourceLoader,
getSolrConfig().getName(), null);
IndexSchema schema = new IndexSchema(config,
coreDescriptor.getSchemaName(), null);
getSchema().getResourceName(), null);
updateHandler.incref();
SolrCore core = new SolrCore(coreDescriptor.getName(), null, config,
SolrCore core = new SolrCore(getName(), null, config,
schema, coreDescriptor, updateHandler);
return core;
}

View File

@ -25,6 +25,7 @@ import org.apache.solr.update.DirectUpdateHandler2;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.xml.sax.SAXParseException;
/**
*
@ -94,13 +95,14 @@ public class BasicZkTest extends AbstractZkTestCase {
assertU(a, a);
}
assertU(commit());
int zkPort = zkServer.getPort();
zkServer.shutdown();
Thread.sleep(300);
// try a reconnect from disconnect
zkServer = new ZkTestServer(zkDir);
zkServer = new ZkTestServer(zkDir, zkPort);
zkServer.run();
Thread.sleep(300);
@ -129,6 +131,20 @@ public class BasicZkTest extends AbstractZkTestCase {
assertU(delQ("id:[100 TO 110]"));
assertU(commit());
assertQ(req("id:[100 TO 110]"), "//*[@numFound='0']");
// SOLR-2651: test that reload still gets config files from zookeeper
zkController.getZkClient().setData("/configs/conf1/solrconfig.xml", new byte[0]);
// we set the solrconfig to nothing, so this reload should fail
try {
h.getCoreContainer().reload(h.getCore().getName());
fail("The reloaded SolrCore did not pick up configs from zookeeper");
} catch(SAXParseException e) {
}
}
@AfterClass

View File

@ -124,6 +124,9 @@ public class TestJmxIntegration extends AbstractSolrTestCase {
int oldNumberOfObjects = oldBeans.size();
h.getCoreContainer().reload(coreName);
// chill for a moment, so our beans can get ready
Thread.sleep(1000);
Set<ObjectInstance> newBeans = mbeanServer.queryMBeans(null, null);
int newNumberOfObjects = newBeans.size();