From b8c727af8de81c30dc230fd27cfdaef045072b5b Mon Sep 17 00:00:00 2001 From: Erick Erickson Date: Thu, 25 Oct 2012 18:25:43 +0000 Subject: [PATCH] Fix for SOLR-3984, unloading core with deleteInstanceDir not working unless path absolute git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1402254 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/core/CoreContainer.java | 13 +------------ .../org/apache/solr/core/CoreDescriptor.java | 18 ++++++++++++++++-- .../org/apache/solr/handler/SnapShooter.java | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) 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 e87aef491f8..51b1553f073 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -34,9 +34,6 @@ import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import javax.xml.parsers.ParserConfigurationException; @@ -59,7 +56,6 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.cloud.ZooKeeperException; -import org.apache.solr.common.util.ExecutorUtil; import org.apache.solr.core.SolrXMLSerializer.SolrCoreXMLDef; import org.apache.solr.core.SolrXMLSerializer.SolrXMLDef; import org.apache.solr.handler.admin.CollectionsHandler; @@ -72,7 +68,6 @@ import org.apache.solr.logging.jul.JulWatcher; import org.apache.solr.schema.IndexSchema; import org.apache.solr.update.SolrCoreState; import org.apache.solr.util.DOMUtil; -import org.apache.solr.util.DefaultSolrThreadFactory; import org.apache.solr.util.FileUtils; import org.apache.solr.util.SystemIdResolver; import org.apache.zookeeper.KeeperException; @@ -760,9 +755,6 @@ public class CoreContainer try { // Make the instanceDir relative to the cores instanceDir if not absolute File idir = new File(dcore.getInstanceDir()); - if (!idir.isAbsolute()) { - idir = new File(solrHome, dcore.getInstanceDir()); - } String instanceDir = idir.getPath(); log.info("Creating SolrCore '{}' using instanceDir: {}", dcore.getName(), instanceDir); @@ -973,9 +965,6 @@ public class CoreContainer CoreDescriptor cd = core.getCoreDescriptor(); File instanceDir = new File(cd.getInstanceDir()); - if (!instanceDir.isAbsolute()) { - instanceDir = new File(getSolrHome(), cd.getInstanceDir()); - } log.info("Reloading SolrCore '{}' using instanceDir: {}", cd.getName(), instanceDir.getAbsolutePath()); @@ -1283,7 +1272,7 @@ public class CoreContainer coreAttribs.put(CORE_NAME, coreName); - String instanceDir = dcore.getInstanceDir(); + String instanceDir = dcore.getRawInstanceDir(); addCoreProperty(coreAttribs, coreNode, CORE_INSTDIR, instanceDir, null); // write config 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 e651540fbda..7b2f4a7af23 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java +++ b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java @@ -130,10 +130,24 @@ public class CoreDescriptor { } /**@return the core instance directory. */ - public String getInstanceDir() { - return instanceDir; + public String getRawInstanceDir() { + return this.instanceDir; } + /** + * + * @return the core instance directory, prepended with solr_home if not an absolute path. + */ + public String getInstanceDir() { + String instDir = this.instanceDir; + if (instDir == null) return null; // No worse than before. + + if (new File(instDir).isAbsolute()) { + return SolrResourceLoader.normalizeDir(SolrResourceLoader.normalizeDir(instanceDir)); + } + return SolrResourceLoader.normalizeDir(coreContainer.getSolrHome() + + SolrResourceLoader.normalizeDir(instDir)); + } /**Sets the core configuration resource name. */ public void setConfigName(String name) { if (name == null || name.length() == 0) diff --git a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java b/solr/core/src/java/org/apache/solr/handler/SnapShooter.java index 996eb9885a3..e3d72bcba7f 100644 --- a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java +++ b/solr/core/src/java/org/apache/solr/handler/SnapShooter.java @@ -57,7 +57,7 @@ public class SnapShooter { solrCore = core; if (location == null) snapDir = core.getDataDir(); else { - File base = new File(core.getCoreDescriptor().getInstanceDir()); + File base = new File(core.getCoreDescriptor().getRawInstanceDir()); snapDir = org.apache.solr.util.FileUtils.resolvePath(base, location).getAbsolutePath(); File dir = new File(snapDir); if (!dir.exists()) dir.mkdirs();