SOLR-3166: Allow bootstrapping multiple config sets from multi-core setups.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1294169 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-02-27 14:50:01 +00:00
parent 4576bc162a
commit b51ee44c39
4 changed files with 174 additions and 2 deletions

View File

@ -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 it
log.info("Only one config set found in zk - using it:" + configNames.get(0));
collectionProps.put(CONFIGNAME_PROP, configNames.get(0));

View File

@ -219,6 +219,12 @@ public class CoreContainer
String 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 status
Thread.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;
}

View File

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

View File

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