diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 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 required reverting 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.java index 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 CoreContainer IndexSchema 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 CoreContainer public 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.xml index 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 --> - + diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java index 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(); + } + } + @Test public void testPersist() throws Exception { final File workDir = new File(TEMP_DIR, this.getClass().getName()