Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

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

Mark Robert Millerd0c71f97027c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5086cda760c..409395eddef 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -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
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 05bf268988a..2698d26bef9 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -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);
}
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index 6d0edd171a8..d3bf1bb2cff 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -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;
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java
index 20c1de8e47b..9029ef56069 100644
--- a/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/BasicZkTest.java
@@ -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
diff --git a/solr/core/src/test/org/apache/solr/core/TestJmxIntegration.java b/solr/core/src/test/org/apache/solr/core/TestJmxIntegration.java
index f62fd2bf4b6..fac042fda65 100644
--- a/solr/core/src/test/org/apache/solr/core/TestJmxIntegration.java
+++ b/solr/core/src/test/org/apache/solr/core/TestJmxIntegration.java
@@ -123,7 +123,10 @@ public class TestJmxIntegration extends AbstractSolrTestCase {
Set<ObjectInstance> oldBeans = mbeanServer.queryMBeans(null, null);
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();