Apache Solr open-source search software
SOLR-3166: Allow bootstrapping multiple config sets from multi-core setups.
Mark Robert Millerb51ee44c39f5
diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.javaindex 62fe8b99bc0..18f4bfb7240 100644--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java@@ -878,6 +878,9 @@ public final class ZkController {if (!collectionProps.containsKey(CONFIGNAME_PROP))collectionProps.put(CONFIGNAME_PROP, defaultConfigName);+ } else if (Boolean.getBoolean("bootstrap_conf")) {+ // the conf name should should be the collection name of this core+ collectionProps.put(CONFIGNAME_PROP, cd.getCollectionName());} else {getConfName(collection, collectionPath, collectionProps);}@@ -920,9 +923,15 @@ public final class ZkController {break;}}+ List<String> configNames = null;// if there is only one conf, use that- List<String> configNames = zkClient.getChildren(CONFIGS_ZKNODE, null, true);- if (configNames.size() == 1) {+ try {+ configNames = zkClient.getChildren(CONFIGS_ZKNODE, null,+ true);+ } catch (NoNodeException e) {+ // just keep trying+ }+ if (configNames != null && configNames.size() == 1) {// no config set named, but there is only 1 - use itlog.info("Only one config set found in zk - using it:" + configNames.get(0));collectionProps.put(CONFIGNAME_PROP, configNames.get(0));diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.javaindex bb33a3fa6e7..9068f329b63 100644--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java@@ -219,6 +219,12 @@ public class CoreContainerString confName = System.getProperty(ZkController.COLLECTION_PARAM_PREFIX+ZkController.CONFIGNAME_PROP, "configuration1");zkController.uploadConfigDir(dir, confName);}++ boolean boostrapConf = Boolean.getBoolean("bootstrap_conf");+ if(boostrapConf) {+ bootstrapConf();+ }+} catch (InterruptedException e) {// Restore the interrupted statusThread.currentThread().interrupt();@@ -242,6 +248,28 @@ public class CoreContainer}+ private void bootstrapConf() throws IOException,+ KeeperException, InterruptedException {++ NodeList nodes = (NodeList)cfg.evaluate("solr/cores/core", XPathConstants.NODESET);++ for (int i=0; i<nodes.getLength(); i++) {+ Node node = nodes.item(i);+ String rawName = DOMUtil.getAttr(node, "name", null);+ String instanceDir = DOMUtil.getAttr(node, "instanceDir", null);+ File idir = new File(instanceDir);+ if (!idir.isAbsolute()) {+ idir = new File(solrHome, instanceDir);+ }+ String confName = DOMUtil.getAttr(node, "collection", null);+ if (confName == null) {+ confName = rawName;+ }++ zkController.uploadConfigDir(new File(idir, "conf"), confName);+ }+ }+public Properties getContainerProperties() {return containerProperties;}diff --git a/solr/core/src/test/org/apache/solr/cloud/TestMultiCoreConfBootstrap.java b/solr/core/src/test/org/apache/solr/cloud/TestMultiCoreConfBootstrap.javanew file mode 100644index 00000000000..558a1046f8b--- /dev/null+++ b/solr/core/src/test/org/apache/solr/cloud/TestMultiCoreConfBootstrap.java@@ -0,0 +1,118 @@+/**+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.cloud;++import java.io.File;+import java.io.IOException;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.common.cloud.SolrZkClient;+import org.apache.solr.core.CoreContainer;+import org.apache.solr.util.AbstractSolrTestCase;+import org.apache.solr.util.ExternalPaths;+import org.junit.After;+import org.junit.AfterClass;+import org.junit.Before;+import org.junit.BeforeClass;+import org.junit.Test;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++public class TestMultiCoreConfBootstrap extends SolrTestCaseJ4 {+ protected static Logger log = LoggerFactory.getLogger(TestMultiCoreConfBootstrap.class);+ protected CoreContainer cores = null;+ private String home;+++ protected static ZkTestServer zkServer;+ protected static String zkDir;++ @BeforeClass+ public static void beforeClass() throws Exception {+ createTempDir();+ }++ @AfterClass+ public static void afterClass() throws IOException {++ }++ @Override+ @Before+ public void setUp() throws Exception {+ super.setUp();+ home = ExternalPaths.EXAMPLE_MULTICORE_HOME;+ System.setProperty("solr.solr.home", home);++ zkDir = dataDir.getAbsolutePath() + File.separator+ + "zookeeper/server1/data";+ zkServer = new ZkTestServer(zkDir);+ zkServer.run();++ SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT);+ zkClient.makePath("/solr", false, true);+ zkClient.close();++ System.setProperty("zkHost", zkServer.getZkAddress());+ }++ @Override+ @After+ public void tearDown() throws Exception {+ System.clearProperty("bootstrap_confdir");+ System.clearProperty("zkHost");+ System.clearProperty("solr.solr.home");++ if (cores != null)+ cores.shutdown();++ zkServer.shutdown();++ File dataDir1 = new File(home + File.separator + "core0","data");+ File dataDir2 = new File(home + File.separator + "core1","data");++ String skip = System.getProperty("solr.test.leavedatadir");+ if (null != skip && 0 != skip.trim().length()) {+ log.info("NOTE: per solr.test.leavedatadir, dataDir will not be removed: " + dataDir.getAbsolutePath());+ } else {+ if (!AbstractSolrTestCase.recurseDelete(dataDir1)) {+ log.warn("!!!! WARNING: best effort to remove " + dataDir.getAbsolutePath() + " FAILED !!!!!");+ }+ if (!AbstractSolrTestCase.recurseDelete(dataDir2)) {+ log.warn("!!!! WARNING: best effort to remove " + dataDir.getAbsolutePath() + " FAILED !!!!!");+ }+ }++ super.tearDown();+ }+++ @Test+ public void testMultiCoreConfBootstrap() throws Exception {+ System.setProperty("bootstrap_conf", "true");+ cores = new CoreContainer(home, new File(home, "solr.xml"));+ SolrZkClient zkclient = cores.getZkController().getZkClient();+ // zkclient.printLayoutToStdOut();++ assertTrue(zkclient.exists("/configs/core1/solrconfig.xml", true));+ assertTrue(zkclient.exists("/configs/core1/schema.xml", true));+ assertTrue(zkclient.exists("/configs/core0/solrconfig.xml", true));+ assertTrue(zkclient.exists("/configs/core1/schema.xml", true));+ }++}diff --git a/solr/example/multicore/zoo.cfg b/solr/example/multicore/zoo.cfgnew file mode 100644index 00000000000..aea451885e4--- /dev/null+++ b/solr/example/multicore/zoo.cfg@@ -0,0 +1,17 @@+# The number of milliseconds of each tick+tickTime=2000+# The number of ticks that the initial+# synchronization phase can take+initLimit=10+# The number of ticks that can pass between+# sending a request and getting an acknowledgement+syncLimit=5++# the directory where the snapshot is stored.+# dataDir=/opt/zookeeper/data+# NOTE: Solr defaults the dataDir to <solrHome>/zoo_data++# the port at which the clients will connect+# clientPort=2181+# NOTE: Solr sets this based on zkRun / zkHost params+