Skip to content

Apache Lucene open-source search software

SOLR-3264: Fix CoreContainer and SolrResourceLoader logging to stop misleading people about SolrCore instanceDir's being the Solr Home Dir

Chris M. Hostetter3f32f09c95da
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index bf270b7adea..14144218ed3 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -729,6 +729,10 @@ Bug Fixes
and was fundamentally broken/bizarre.
(hossman, Ahmet Arslan)
+* SOLR-3264: Fix CoreContainer and SolrResourceLoader logging to be more
+ clear about when SolrCores are being created, and stop misleading people
+ about SolrCore instanceDir's being the "Solr Home Dir" (hossman)
+
Other Changes
----------------------
* SOLR-2922: Upgrade commons-io and commons-lang to 2.1 and 2.6, respectively. (koji)
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 9068f329b63..7862e1c3045 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -123,8 +123,14 @@ public class CoreContainer
log.info("New CoreContainer " + System.identityHashCode(this));
}
+ /**
+ * Deprecated
+ * @deprecated use the single arg constructure with locateSolrHome()
+ * @see SolrResourceLoader#locateSolrHome
+ */
+ @Deprecated
public CoreContainer() {
- solrHome = SolrResourceLoader.locateSolrHome();
+ this(SolrResourceLoader.locateSolrHome());
}
/**
@@ -138,6 +144,7 @@ public class CoreContainer
*/
public CoreContainer(String dir, File configFile) throws ParserConfigurationException, IOException, SAXException
{
+ this(dir);
this.load(dir, configFile);
}
@@ -146,8 +153,8 @@ public class CoreContainer
* @param loader the CoreContainer resource loader
*/
public CoreContainer(SolrResourceLoader loader) {
+ this(loader.getInstanceDir());
this.loader = loader;
- this.solrHome = loader.getInstanceDir();
}
public CoreContainer(String solrHome) {
@@ -287,7 +294,7 @@ public class CoreContainer
File fconf = new File(solrHome, containerConfigFilename == null ? "solr.xml"
: containerConfigFilename);
log.info("looking for solr.xml: " + fconf.getAbsolutePath());
- cores = new CoreContainer();
+ cores = new CoreContainer(solrHome);
if (fconf.exists()) {
cores.load(solrHome, fconf);
@@ -355,6 +362,13 @@ public class CoreContainer
*/
public void load(String dir, InputSource cfgis)
throws ParserConfigurationException, IOException, SAXException {
+
+ if (null == dir) {
+ // don't rely on SolrResourceLoader(), determine explicitly first
+ dir = SolrResourceLoader.locateSolrHome();
+ }
+ log.info("Loading CoreContainer using Solr Home: '{}'", dir);
+
this.loader = new SolrResourceLoader(dir);
solrHome = loader.getInstanceDir();
@@ -675,7 +689,8 @@ public class CoreContainer
idir = new File(solrHome, dcore.getInstanceDir());
}
String instanceDir = idir.getPath();
-
+ log.info("Creating SolrCore '{}' using instanceDir: {}",
+ dcore.getName(), instanceDir);
// Initialize the solr config
SolrResourceLoader solrLoader = null;
@@ -831,6 +846,9 @@ public class CoreContainer
if (!instanceDir.isAbsolute()) {
instanceDir = new File(getSolrHome(), cd.getInstanceDir());
}
+
+ log.info("Reloading SolrCore '{}' using instanceDir: {}",
+ cd.getName(), instanceDir.getAbsolutePath());
SolrResourceLoader solrLoader;
if(zkController == null) {
@@ -956,7 +974,8 @@ public class CoreContainer
* @return a CoreAdminHandler
*/
protected CoreAdminHandler createMultiCoreHandler(final String adminHandlerClass) {
- SolrResourceLoader loader = new SolrResourceLoader(null, libLoader, null);
+ // :TODO: why create a new SolrResourceLoader? why not use this.loader ???
+ SolrResourceLoader loader = new SolrResourceLoader(solrHome, libLoader, null);
Object obj = loader.newAdminHandlerInstance(CoreContainer.this, adminHandlerClass);
if ( !(obj instanceof CoreAdminHandler))
{
diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
index 302c317ec2e..b67de6ea34e 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
@@ -88,17 +88,22 @@ public class SolrResourceLoader implements ResourceLoader
* This loader will delegate to the context classloader when possible,
* otherwise it will attempt to resolve resources using any jar files
* found in the "lib/" directory in the specified instance directory.
- * If the instance directory is not specified (=null), SolrResourceLoader#locateInstanceDir will provide one.
- * <p>
+ * </p>
+ *
+ * @param instanceDir - base directory for this resource loader, if null locateSolrHome() will be used.
+ * @see #locateSolrHome
*/
public SolrResourceLoader( String instanceDir, ClassLoader parent, Properties coreProperties )
{
if( instanceDir == null ) {
this.instanceDir = SolrResourceLoader.locateSolrHome();
+ log.info("new SolrResourceLoader for deduced Solr Home: '{}'",
+ this.instanceDir);
} else{
this.instanceDir = normalizeDir(instanceDir);
+ log.info("new SolrResourceLoader for directory: '{}'",
+ this.instanceDir);
}
- log.info("Solr home set to '" + this.instanceDir + "'");
this.classLoader = createClassLoader(null, parent);
addToClassLoader("./lib/", null);
@@ -607,6 +612,7 @@ public class SolrResourceLoader implements ResourceLoader
* @see #normalizeDir(String)
*/
public static String locateSolrHome() {
+
String home = null;
// Try JNDI
try {