From d17cf48d13f47fbcde575668a577e0300c3feda4 Mon Sep 17 00:00:00 2001 From: Shalin Shekhar Mangar Date: Fri, 6 Feb 2009 09:24:51 +0000 Subject: [PATCH] SOLR-943 -- Make it possible to specify dataDir in solr.xml and accept the dataDir as a request parameter for the CoreAdmin create command. git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@741490 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 +++ .../solr/common/params/CoreAdminParams.java | 5 ++++- .../org/apache/solr/core/CoreContainer.java | 5 +++++ .../org/apache/solr/core/CoreDescriptor.java | 21 +++++++++++++++++-- src/java/org/apache/solr/core/SolrCore.java | 2 +- .../solr/handler/admin/CoreAdminHandler.java | 4 +++- 6 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 6a8445cff47..bef0a079038 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -147,6 +147,9 @@ New Features 33. SOLR-820: Support replication on startup of master with new index. (Noble Paul, Akshay Ukey via shalin) +34. SOLR-943: Make it possible to specify dataDir in solr.xml and accept the dataDir as a request parameter for + the CoreAdmin create command. (Noble Paul via shalin) + Optimizations ---------------------- diff --git a/src/common/org/apache/solr/common/params/CoreAdminParams.java b/src/common/org/apache/solr/common/params/CoreAdminParams.java index 1d85b2fdad2..4c8c1382677 100644 --- a/src/common/org/apache/solr/common/params/CoreAdminParams.java +++ b/src/common/org/apache/solr/common/params/CoreAdminParams.java @@ -32,6 +32,9 @@ public interface CoreAdminParams /** If you rename something, what is the new name **/ public final static String NAME = "name"; + /** If you rename something, what is the new name **/ + public final static String DATA_DIR = "dataDir"; + /** Name of the other core in actions involving 2 cores **/ public final static String OTHER = "other"; @@ -72,4 +75,4 @@ public interface CoreAdminParams return null; } } -} \ No newline at end of file +} diff --git a/src/java/org/apache/solr/core/CoreContainer.java b/src/java/org/apache/solr/core/CoreContainer.java index e219b65a56e..561d8222a25 100644 --- a/src/java/org/apache/solr/core/CoreContainer.java +++ b/src/java/org/apache/solr/core/CoreContainer.java @@ -35,6 +35,7 @@ import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpressionException; import org.apache.solr.common.SolrException; +import org.apache.solr.common.params.CoreAdminParams; import org.apache.solr.common.util.DOMUtil; import org.apache.solr.common.util.XML; import org.apache.solr.common.util.StrUtils; @@ -212,6 +213,10 @@ public class CoreContainer if (opt != null) { p.setSchemaName(opt); } + opt = DOMUtil.getAttr(node, CoreAdminParams.DATA_DIR, null); + if (opt != null) { + p.setDataDir(opt); + } p.setCoreProperties(readProperties(cfg, node)); diff --git a/src/java/org/apache/solr/core/CoreDescriptor.java b/src/java/org/apache/solr/core/CoreDescriptor.java index aa7af9ed81e..fa48aacec07 100644 --- a/src/java/org/apache/solr/core/CoreDescriptor.java +++ b/src/java/org/apache/solr/core/CoreDescriptor.java @@ -18,6 +18,7 @@ package org.apache.solr.core; import java.util.Properties; +import java.io.File; /** * A Solr core descriptor @@ -27,6 +28,7 @@ import java.util.Properties; public class CoreDescriptor implements Cloneable { protected String name; protected String instanceDir; + protected String dataDir; protected String configName; protected String schemaName; private final CoreContainer coreContainer; @@ -52,6 +54,7 @@ public class CoreDescriptor implements Cloneable { this.configName = descr.configName; this.schemaName = descr.schemaName; this.name = descr.name; + this.dataDir = descr.dataDir; coreContainer = descr.coreContainer; } @@ -59,6 +62,7 @@ public class CoreDescriptor implements Cloneable { Properties implicitProperties = new Properties(coreContainer.getContainerProperties()); implicitProperties.setProperty("solr.core.name", name); implicitProperties.setProperty("solr.core.instanceDir", instanceDir); + implicitProperties.setProperty("solr.core.dataDir", getDataDir()); implicitProperties.setProperty("solr.core.configName", configName); implicitProperties.setProperty("solr.core.schemaName", schemaName); return implicitProperties; @@ -76,9 +80,22 @@ public class CoreDescriptor implements Cloneable { /**@return the default data directory. */ public String getDefaultDataDir() { - return this.instanceDir + "data/"; + return this.instanceDir + "data"+File.separator; } - + + public String getDataDir() { + if (dataDir == null) return getDefaultDataDir(); + String absolutePath = new File(dataDir).getAbsolutePath(); + if (absolutePath.equals(dataDir) || (absolutePath + File.separator).equals(dataDir)) return dataDir; + return dataDir.endsWith(File.separator) ? + instanceDir + dataDir : + instanceDir + dataDir + File.separator; + } + + public void setDataDir(String s) { + dataDir = s; + } + /**@return the core instance directory. */ public String getInstanceDir() { return instanceDir; diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java index 5a62a82e0e5..7be037e5512 100644 --- a/src/java/org/apache/solr/core/SolrCore.java +++ b/src/java/org/apache/solr/core/SolrCore.java @@ -491,7 +491,7 @@ public final class SolrCore implements SolrInfoMBean { this.setName( name ); SolrResourceLoader loader = config.getResourceLoader(); if (dataDir == null) - dataDir = config.get("dataDir",loader.getInstanceDir()+"data/"); + dataDir = config.get("dataDir",cd.getDataDir()); dataDir = SolrResourceLoader.normalizeDir(dataDir); diff --git a/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java index f2d1a425f07..72234ee7d5a 100644 --- a/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java +++ b/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java @@ -103,7 +103,9 @@ public abstract class CoreAdminHandler extends RequestHandlerBase if (opts != null) dcore.setSchemaName(opts); - dcore.setCoreProperties(null); + opts = params.get(CoreAdminParams.DATA_DIR); + if (opts != null) + dcore.setDataDir(opts); SolrCore core = cores.create(dcore); cores.register(name, core,false);