Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Fix for SOLR-4575, solr.core.* no longer respected when evaluating config files

Erick Erickson55cb4b443f5f
diff --git a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
index 8fddec520f6..f2648d21d0a 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
@@ -64,6 +64,8 @@ public class CoreDescriptor {
// them individually.
private Properties coreProperties = new Properties();
+ private boolean loadedImplicit = false;
+
private final CoreContainer coreContainer;
private CloudDescriptor cloudDesc;
@@ -133,11 +135,11 @@ public class CoreDescriptor {
public Properties initImplicitProperties() {
Properties implicitProperties = new Properties(coreContainer.getContainerProperties());
- implicitProperties.setProperty(CORE_NAME, getName());
- implicitProperties.setProperty(CORE_INSTDIR, getInstanceDir());
- implicitProperties.setProperty(CORE_DATADIR, getDataDir());
- implicitProperties.setProperty(CORE_CONFIG, getConfigName());
- implicitProperties.setProperty(CORE_SCHEMA, getSchemaName());
+ implicitProperties.setProperty("solr.core.name", getName());
+ implicitProperties.setProperty("solr.core.instanceDir", getInstanceDir());
+ implicitProperties.setProperty("solr.core.dataDir", getDataDir());
+ implicitProperties.setProperty("solr.core.configName", getConfigName());
+ implicitProperties.setProperty("solr.core.schemaName", getSchemaName());
return implicitProperties;
}
@@ -251,13 +253,14 @@ public class CoreDescriptor {
* Under any circumstance, the properties passed in will override any already present.Merge
*/
public void setCoreProperties(Properties coreProperties) {
- if (this.coreProperties == null) {
+ if (! loadedImplicit) {
+ loadedImplicit = true;
Properties p = initImplicitProperties();
- this.coreProperties = new Properties(p);
- }
- // The caller presumably wants whatever properties passed in to override the current core props, so just add them.
- if(coreProperties != null) {
- this.coreProperties.putAll(coreProperties);
+ this.coreProperties.putAll(p);
+ // The caller presumably wants whatever properties passed in to override the current core props, so just add them.
+ if (coreProperties != null) {
+ this.coreProperties.putAll(coreProperties);
+ }
}
}
diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrDiscoveryProperties.java b/solr/core/src/test/org/apache/solr/core/TestSolrDiscoveryProperties.java
index 4ab7619101d..e97101533e1 100644
--- a/solr/core/src/test/org/apache/solr/core/TestSolrDiscoveryProperties.java
+++ b/solr/core/src/test/org/apache/solr/core/TestSolrDiscoveryProperties.java
@@ -163,6 +163,18 @@ public class TestSolrDiscoveryProperties extends SolrTestCaseJ4 {
TestLazyCores.checkNotInCores(cc, "lazy1", "core2", "collection1");
SolrCore core1 = cc.getCore("core1");
+
+ // Let's assert we did the right thing for implicit properties too.
+ CoreDescriptor desc = core1.getCoreDescriptor();
+ assertEquals("core1", desc.getProperty("solr.core.name"));
+
+ // This is too long and ugly to put in. Besides, it varies.
+ assertNotNull(desc.getProperty("solr.core.instanceDir"));
+
+ assertEquals("stuffandnonsense", desc.getProperty("solr.core.dataDir"));
+ assertEquals("solrconfig-minimal.xml", desc.getProperty("solr.core.configName"));
+ assertEquals("schema-tiny.xml", desc.getProperty("solr.core.schemaName"));
+
SolrCore core2 = cc.getCore("core2");
SolrCore lazy1 = cc.getCore("lazy1");
TestLazyCores.checkInCores(cc, "core1", "core2", "lazy1");
@@ -386,6 +398,19 @@ public class TestSolrDiscoveryProperties extends SolrTestCaseJ4 {
assertNull(props.getProperty("port")); // getProperty actually looks at original props.
assertNull(props.getProperty("cores.hostContext"));
assertNull(props.getProperty("cores.zkClientTimeout"));
+
+ SolrCore core1 = cc.getCore("collection1");
+ CoreDescriptor desc = core1.getCoreDescriptor();
+
+ assertEquals("collection1", desc.getProperty("solr.core.name"));
+
+ // This is too long and ugly to put in. Besides, it varies.
+ assertNotNull(desc.getProperty("solr.core.instanceDir"));
+
+ assertEquals("data/", desc.getProperty("solr.core.dataDir"));
+ assertEquals("solrconfig-minimal.xml", desc.getProperty("solr.core.configName"));
+ assertEquals("schema-tiny.xml", desc.getProperty("solr.core.schemaName"));
+ core1.close();
} finally {
cc.shutdown();
}