Apache Solr open-source search software
SOLR-3827: Fix shareSchema=true in solr.xml
Chris M. Hostettere8c6d5b24218
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex f86b900a613..13e63ba605e 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -152,6 +152,9 @@ Bug Fixes* SOLR-3823: Fix 'bq' parsing in edismax. Please note that this requiredreverting the negative boost support added by SOLR-3278 (hossman)+* SOLR-3827: Fix shareSchema=true in solr.xml+ (Tomás Fernández Löbbe via hossman)+Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.javaindex 7b52ce56bfb..c8d870cc823 100644--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java@@ -837,7 +837,7 @@ public class CoreContainerIndexSchema schema = null;if (indexSchemaCache != null) {- if (zkController != null) {+ if (zkController == null) {File schemaFile = new File(dcore.getSchemaName());if (!schemaFile.isAbsolute()) {schemaFile = new File(solrLoader.getInstanceDir() + "conf"@@ -1435,6 +1435,10 @@ public class CoreContainerpublic ZkController getZkController() {return zkController;}++ public boolean isShareSchema() {+ return shareSchema;+ }/** The default ShardHandlerFactory used to communicate with other solr instances */public ShardHandlerFactory getShardHandlerFactory() {diff --git a/solr/core/src/test-files/solr/solr.xml b/solr/core/src/test-files/solr/solr.xmlindex 3045891fe29..e2953442f4e 100644--- a/solr/core/src/test-files/solr/solr.xml+++ b/solr/core/src/test-files/solr/solr.xml@@ -28,7 +28,7 @@adminPath: RequestHandler path to manage cores.If 'null' (or absent), cores will not be manageable via request handler-->- <cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}" hostContext="solr" zkClientTimeout="8000" numShards="${numShards:3}">+ <cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}" hostContext="solr" zkClientTimeout="8000" numShards="${numShards:3}" shareSchema="${shareSchema:false}"><core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"/></cores></solr>diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.javaindex 6a676b1d0a9..0a59977ee23 100644--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java@@ -40,7 +40,41 @@ public class TestCoreContainer extends SolrTestCaseJ4 {public static void beforeClass() throws Exception {initCore("solrconfig.xml", "schema.xml");}-+++ public void testShareSchema() throws IOException, ParserConfigurationException, SAXException {+ final File workDir = new File(TEMP_DIR, this.getClass().getName());++ if (workDir.exists()) {+ FileUtils.deleteDirectory(workDir);+ }+ assertTrue("Failed to mkdirs workDir", workDir.mkdirs());++ String solrHome = SolrResourceLoader.locateSolrHome();+ File fconf = new File(solrHome, "solr.xml");++ final CoreContainer cores = new CoreContainer(solrHome);+ System.setProperty("shareSchema", "true");+ cores.load(solrHome, fconf);+ try {+ cores.setPersistent(false);+ assertTrue(cores.isShareSchema());++ CoreDescriptor descriptor1 = new CoreDescriptor(cores, "core1", "./collection1");+ SolrCore core1 = cores.create(descriptor1);++ CoreDescriptor descriptor2 = new CoreDescriptor(cores, "core2", "./collection1");+ SolrCore core2 = cores.create(descriptor2);++ assertSame(core1.getSchema(), core2.getSchema());++ core1.close();+ core2.close();+ } finally {+ cores.shutdown();+ }+ }+@Testpublic void testPersist() throws Exception {final File workDir = new File(TEMP_DIR, this.getClass().getName()