SOLR-11037: Refactor to provide NodeConfig.getSolrDataHome internal API.

This commit is contained in:
Andrzej Bialecki 2017-07-19 09:09:24 +02:00
parent bddbef0ce9
commit 541aa719c4
7 changed files with 45 additions and 10 deletions

View File

@ -549,6 +549,8 @@ Other Changes
* SOLR-11088: Fix sporadic failures of MetricsHandlerTest.testPropertyFilter on jenkins (shalin)
* SOLR-11037: Refactor to provide NodeConfig.getSolrDataHome internal API. (ab, janhoy, shalin)
================== 6.7.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -397,13 +397,12 @@ public abstract class CachingDirectoryFactory extends DirectoryFactory {
maxWriteMBPerSecRead = (Double) args.get("maxWriteMBPerSecRead");
maxWriteMBPerSecDefault = (Double) args.get("maxWriteMBPerSecDefault");
dataHomePath = args.get(DATA_HOME) == null ? null : Paths.get((String) args.get(DATA_HOME));
if (dataHomePath == null && System.getProperty(DATA_HOME) != null && System.getProperty(DATA_HOME).length() > 0) {
// If solr.data.home is not specified explicitly in solrconfig.xml, fall back to global System Property with same name
dataHomePath = Paths.get(System.getProperty(DATA_HOME));
// override global config
if (args.get(SolrXmlConfig.SOLR_DATA_HOME) != null) {
dataHomePath = Paths.get((String) args.get(SolrXmlConfig.SOLR_DATA_HOME));
}
if (dataHomePath != null) {
log.info(DATA_HOME + "=" + dataHomePath);
log.info(SolrXmlConfig.SOLR_DATA_HOME + "=" + dataHomePath);
}
}

View File

@ -55,8 +55,6 @@ public abstract class DirectoryFactory implements NamedListInitializedPlugin,
protected static final String INDEX_W_TIMESTAMP_REGEX = "index\\.[0-9]{17}"; // see SnapShooter.DATE_FMT
public static final String DATA_HOME = "solr.data.home";
// May be set by sub classes as data root, in which case getDataHome will use it as base
protected Path dataHomePath;
@ -394,6 +392,9 @@ public abstract class DirectoryFactory implements NamedListInitializedPlugin,
public void initCoreContainer(CoreContainer cc) {
this.coreContainer = cc;
if (cc != null && cc.getConfig() != null) {
this.dataHomePath = cc.getConfig().getSolrDataHome();
}
}
// special hack to work with FilterDirectory

View File

@ -33,6 +33,8 @@ public class NodeConfig {
private final Path coreRootDirectory;
private final Path solrDataHome;
private final Path configSetBaseDirectory;
private final String sharedLibDirectory;
@ -69,7 +71,7 @@ public class NodeConfig {
private final PluginInfo transientCacheConfig;
private NodeConfig(String nodeName, Path coreRootDirectory, Path configSetBaseDirectory, String sharedLibDirectory,
private NodeConfig(String nodeName, Path coreRootDirectory, Path solrDataHome, Path configSetBaseDirectory, String sharedLibDirectory,
PluginInfo shardHandlerFactoryConfig, UpdateShardHandlerConfig updateShardHandlerConfig,
String coreAdminHandlerClass, String collectionsAdminHandlerClass,
String infoHandlerClass, String configSetsHandlerClass,
@ -79,6 +81,7 @@ public class NodeConfig {
MetricsConfig metricsConfig, PluginInfo transientCacheConfig) {
this.nodeName = nodeName;
this.coreRootDirectory = coreRootDirectory;
this.solrDataHome = solrDataHome;
this.configSetBaseDirectory = configSetBaseDirectory;
this.sharedLibDirectory = sharedLibDirectory;
this.shardHandlerFactoryConfig = shardHandlerFactoryConfig;
@ -113,6 +116,10 @@ public class NodeConfig {
return coreRootDirectory;
}
public Path getSolrDataHome() {
return solrDataHome;
}
public PluginInfo getShardHandlerFactoryPluginInfo() {
return shardHandlerFactoryConfig;
}
@ -195,6 +202,7 @@ public class NodeConfig {
public static class NodeConfigBuilder {
private Path coreRootDirectory;
private Path solrDataHome;
private Path configSetBaseDirectory;
private String sharedLibDirectory = "lib";
private PluginInfo shardHandlerFactoryConfig;
@ -242,6 +250,11 @@ public class NodeConfig {
this.nodeName = nodeName;
this.loader = loader;
this.coreRootDirectory = loader.getInstancePath();
// always init from sysprop because <solrDataHome> config element may be missing
String dataHomeProperty = System.getProperty(SolrXmlConfig.SOLR_DATA_HOME);
if (dataHomeProperty != null && !dataHomeProperty.isEmpty()) {
solrDataHome = loader.getInstancePath().resolve(dataHomeProperty);
}
this.configSetBaseDirectory = loader.getInstancePath().resolve("configsets");
this.metricsConfig = new MetricsConfig.MetricsConfigBuilder().build();
}
@ -251,6 +264,11 @@ public class NodeConfig {
return this;
}
public NodeConfigBuilder setSolrDataHome(String solrDataHomeString) {
this.solrDataHome = loader.getInstancePath().resolve(solrDataHomeString);
return this;
}
public NodeConfigBuilder setConfigSetBaseDirectory(String configSetBaseDirectory) {
this.configSetBaseDirectory = loader.getInstancePath().resolve(configSetBaseDirectory);
return this;
@ -344,7 +362,7 @@ public class NodeConfig {
}
public NodeConfig build() {
return new NodeConfig(nodeName, coreRootDirectory, configSetBaseDirectory, sharedLibDirectory, shardHandlerFactoryConfig,
return new NodeConfig(nodeName, coreRootDirectory, solrDataHome, configSetBaseDirectory, sharedLibDirectory, shardHandlerFactoryConfig,
updateShardHandlerConfig, coreAdminHandlerClass, collectionsAdminHandlerClass, infoHandlerClass, configSetsHandlerClass,
logWatcherConfig, cloudConfig, coreLoadThreads, transientCacheSize, useSchemaCache, managementPath, loader, solrProperties,
backupRepositoryPlugins, metricsConfig, transientCacheConfig);

View File

@ -59,6 +59,7 @@ import static org.apache.solr.common.params.CommonParams.NAME;
public class SolrXmlConfig {
public final static String SOLR_XML_FILE = "solr.xml";
public final static String SOLR_DATA_HOME = "solr.data.home";
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@ -249,6 +250,9 @@ public class SolrXmlConfig {
case "coreRootDirectory":
builder.setCoreRootDirectory(value);
break;
case "solrDataHome":
builder.setSolrDataHome(value);
break;
case "managementPath":
builder.setManagementPath(value);
break;

View File

@ -65,6 +65,9 @@ public class DirectoryFactoryTest extends LuceneTestCase {
// solr.data.home set with System property, and relative path
System.setProperty("solr.data.home", "solrdata");
cc = new MockCoreContainer("/solr/home");
rdf = new RAMDirectoryFactory();
rdf.initCoreContainer(cc);
rdf.init(new NamedList());
assertDataHome("/solr/home/solrdata/inst_dir/data", "inst_dir", rdf, cc);
// Test parsing last component of instanceDir, and using custom dataDir
@ -80,9 +83,11 @@ public class DirectoryFactoryTest extends LuceneTestCase {
private static class MockCoreContainer extends CoreContainer {
private final String mockSolrHome;
private final NodeConfig mockConfig;
public MockCoreContainer(String solrHome) throws IOException {
super(new Object());
mockConfig = new NodeConfig.NodeConfigBuilder("test", new SolrResourceLoader(Paths.get(solrHome))).build();
mockSolrHome = solrHome;
this.shardHandlerFactory = new HttpShardHandlerFactory();
this.coreAdminHandler = new CoreAdminHandler();
@ -92,6 +97,11 @@ public class DirectoryFactoryTest extends LuceneTestCase {
public String getSolrHome() {
return mockSolrHome;
}
@Override
public NodeConfig getConfig() {
return mockConfig;
}
}
}

View File

@ -33,7 +33,8 @@ The `${solr.core.name}` substitution will cause the name of the current core to
If you are using replication to replicate the Solr index (as described in <<legacy-scaling-and-distribution.adoc#legacy-scaling-and-distribution,Legacy Scaling and Distribution>>), then the `<dataDir>` directory should correspond to the index directory used in the replication configuration.
NOTE: If the environment variable `SOLR_DATA_HOME` if defined, or if `solr.data.home` is configured for your DirectoryFactory, the location of data directory will be `<SOLR_DATA_HOME>/<instance_name>/data`.
NOTE: If the environment variable `SOLR_DATA_HOME` is defined, or if `solr.data.home` is configured for your DirectoryFactory, or if `solr.xml` contains an
element `<solrDataHome>` then the location of data directory will be `<SOLR_DATA_HOME>/<instance_name>/data`.
== Specifying the DirectoryFactory For Your Index