lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject lucene-solr:branch_7x: SOLR-11037: Refactor to provide NodeConfig.getSolrDataHome internal API.
Date Wed, 19 Jul 2017 08:15:19 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 2fd49e17c -> f297841b4


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


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/f297841b
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/f297841b
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/f297841b

Branch: refs/heads/branch_7x
Commit: f297841b4eee83a6ca2a9fa10b8ecec4f26e9773
Parents: 2fd49e1
Author: Andrzej Bialecki <ab@apache.org>
Authored: Wed Jul 19 09:09:24 2017 +0200
Committer: Andrzej Bialecki <ab@apache.org>
Committed: Wed Jul 19 10:14:58 2017 +0200

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 ++
 .../solr/core/CachingDirectoryFactory.java      |  9 ++++----
 .../org/apache/solr/core/DirectoryFactory.java  |  5 +++--
 .../java/org/apache/solr/core/NodeConfig.java   | 22 ++++++++++++++++++--
 .../org/apache/solr/core/SolrXmlConfig.java     |  4 ++++
 .../apache/solr/core/DirectoryFactoryTest.java  | 10 +++++++++
 ...adir-and-directoryfactory-in-solrconfig.adoc |  3 ++-
 7 files changed, 45 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f297841b/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 48cde93..0d9a96a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -530,6 +530,8 @@ Other Changes
 * SOLR-11068: MOVEREPLICA and REPLACENODE API parameter names are now 'sourceNode' and 'targetNode'.
The old names
   viz. 'fromNode' for MOVEREPLICA and 'source', 'target' for REPLACENODE have been deprecated.
(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.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f297841b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
----------------------------------------------------------------------
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 5301370..8b8c740 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);
     }
   }
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f297841b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java
----------------------------------------------------------------------
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 f60958d..e7e33a5 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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f297841b/solr/core/src/java/org/apache/solr/core/NodeConfig.java
----------------------------------------------------------------------
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 2b70130..fb52e4f 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 <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);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f297841b/solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
----------------------------------------------------------------------
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 e783a89..8cdf947 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;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f297841b/solr/core/src/test/org/apache/solr/core/DirectoryFactoryTest.java
----------------------------------------------------------------------
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 aa00342..18f0e87 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;
+    }
   }
 
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f297841b/solr/solr-ref-guide/src/datadir-and-directoryfactory-in-solrconfig.adoc
----------------------------------------------------------------------
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 f3e8dc9..d36d781 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 <<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
 


Mime
View raw message