diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 45f38300d0a..a069fa1a433 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -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. diff --git a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java index 5301370a59d..8b8c740523b 100644 --- a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java @@ -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); } } diff --git a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java index f60958df592..e7e33a56992 100644 --- a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java @@ -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 diff --git a/solr/core/src/java/org/apache/solr/core/NodeConfig.java b/solr/core/src/java/org/apache/solr/core/NodeConfig.java index 2b7013053ae..fb52e4fe4e4 100644 --- a/solr/core/src/java/org/apache/solr/core/NodeConfig.java +++ b/solr/core/src/java/org/apache/solr/core/NodeConfig.java @@ -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 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); diff --git a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java index e783a89490c..8cdf94773e9 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java +++ b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java @@ -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; diff --git a/solr/core/src/test/org/apache/solr/core/DirectoryFactoryTest.java b/solr/core/src/test/org/apache/solr/core/DirectoryFactoryTest.java index aa00342116d..18f0e870b03 100755 --- a/solr/core/src/test/org/apache/solr/core/DirectoryFactoryTest.java +++ b/solr/core/src/test/org/apache/solr/core/DirectoryFactoryTest.java @@ -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; + } } } diff --git a/solr/solr-ref-guide/src/datadir-and-directoryfactory-in-solrconfig.adoc b/solr/solr-ref-guide/src/datadir-and-directoryfactory-in-solrconfig.adoc index f3e8dc969ff..d36d7817024 100644 --- a/solr/solr-ref-guide/src/datadir-and-directoryfactory-in-solrconfig.adoc +++ b/solr/solr-ref-guide/src/datadir-and-directoryfactory-in-solrconfig.adoc @@ -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 <>), then the `` 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 `//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 `` then the location of data directory will be `//data`. == Specifying the DirectoryFactory For Your Index