mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
604267e448
commit
d17cf48d13
|
@ -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
|
||||
----------------------
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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,7 +80,20 @@ 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. */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue