You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2020/12/03 00:19:13 UTC

[lucene-solr] branch master updated: SOLR-14934: Remove redundent deprecated "solr.solr.home" logic

This is an automated email from the ASF dual-hosted git repository.

hossman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 5208d47  SOLR-14934: Remove redundent deprecated "solr.solr.home" logic
5208d47 is described below

commit 5208d47e1a2030dc51396db74d42b52ba378756d
Author: Chris Hostetter <ho...@apache.org>
AuthorDate: Wed Dec 2 17:18:58 2020 -0700

    SOLR-14934: Remove redundent deprecated "solr.solr.home" logic
---
 solr/CHANGES.txt                                   |  2 +
 .../src/java/org/apache/solr/core/SolrPaths.java   | 62 ----------------------
 .../org/apache/solr/core/SolrResourceLoader.java   | 26 ++-------
 .../apache/solr/servlet/SolrDispatchFilter.java    | 56 +++++++++++++++++--
 4 files changed, 59 insertions(+), 87 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 84c6cdc..2d53968 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -151,6 +151,8 @@ Other Changes
 * SOLR-14035: Remove deprecated preferLocalShards=true support in favour of the shards.preference=replica.location:local alternative.
   (Alex Bulygin via Christine Poerschke)
 
+* SOLR-14934: Remove redundent deprecated "solr.solr.home" logic (hossman)
+
 Bug Fixes
 ---------------------
 * SOLR-14546: Fix for a relatively hard to hit issue in OverseerTaskProcessor that could lead to out of order execution
diff --git a/solr/core/src/java/org/apache/solr/core/SolrPaths.java b/solr/core/src/java/org/apache/solr/core/SolrPaths.java
index ad1d818..b69ae5c 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrPaths.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrPaths.java
@@ -17,16 +17,11 @@
 
 package org.apache.solr.core;
 
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.naming.NoInitialContextException;
 import java.io.File;
 import java.lang.invoke.MethodHandles;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Set;
-import java.util.concurrent.ConcurrentSkipListSet;
 
 import org.apache.commons.exec.OS;
 import org.apache.solr.common.SolrException;
@@ -39,72 +34,15 @@ import org.slf4j.LoggerFactory;
 public final class SolrPaths {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-  private static final Set<String> loggedOnce = new ConcurrentSkipListSet<>();
-
   private SolrPaths() {} // don't create this
 
   /**
-   * Finds the solrhome based on looking up the value in one of three places:
-   * <ol>
-   * <li>JNDI: via java:comp/env/solr/home</li>
-   * <li>The system property solr.solr.home</li>
-   * <li>Look in the current working directory for a solr/ directory</li>
-   * </ol>
-   * <p>
-   *
-   * @return the Solr home, absolute and normalized.
-   * @deprecated all code should get solr home from CoreContainer
-   * @see CoreContainer#getSolrHome()
-   */
-  @Deprecated
-  public static Path locateSolrHome() {
-    
-    String home = null;
-    // Try JNDI
-    try {
-      Context c = new InitialContext();
-      home = (String) c.lookup("java:comp/env/solr/home");
-      logOnceInfo("home_using_jndi", "Using JNDI solr.home: " + home);
-    } catch (NoInitialContextException e) {
-      log.debug("JNDI not configured for solr (NoInitialContextEx)");
-    } catch (NamingException e) {
-      log.debug("No /solr/home in JNDI");
-    } catch (RuntimeException ex) {
-      log.warn("Odd RuntimeException while testing for JNDI: ", ex);
-    }
-
-    // Now try system property
-    if (home == null) {
-      String prop = "solr.solr.home";
-      home = System.getProperty(prop);
-      if (home != null) {
-        logOnceInfo("home_using_sysprop", "Using system property " + prop + ": " + home);
-      }
-    }
-
-    // if all else fails, try
-    if (home == null) {
-      home = "solr/";
-      logOnceInfo("home_default", "solr home defaulted to '" + home + "' (could not find system property or JNDI)");
-    }
-    return Paths.get(home).toAbsolutePath().normalize();
-  }
-
-  /**
    * Ensures a directory name always ends with a '/'.
    */
   public static String normalizeDir(String path) {
     return (path != null && (!(path.endsWith("/") || path.endsWith("\\")))) ? path + File.separator : path;
   }
 
-  // Logs a message only once per startup
-  private static void logOnceInfo(String key, String msg) {
-    if (!loggedOnce.contains(key)) {
-      loggedOnce.add(key);
-      log.info(msg);
-    }
-  }
-
   /**
    * Checks that the given path is relative to one of the allowPaths supplied. Typically this will be
    * called from {@link CoreContainer#assertPathAllowed(Path)} and allowPaths pre-filled with the node's
diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
index cae6281..fa183c6 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
@@ -130,18 +130,8 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
   }
 
   /**
-   * @deprecated Use <code>new SolrResourceLoader(Path)</code>
-   * @see CoreContainer#getSolrHome
-   */
-  @Deprecated
-  public SolrResourceLoader() {
-    this(SolrPaths.locateSolrHome(), null);
-  }
-
-  /**
    * Creates a loader.
    * Note: we do NOT call {@link #reloadLuceneSPI()}.
-   * (Behavior when <code>instanceDir</code> is <code>null</code> is un-specified, in future versions this will fail due to NPE)
    */
   public SolrResourceLoader(String name, List<Path> classpath, Path instanceDir, ClassLoader parent) {
     this(instanceDir, parent);
@@ -160,7 +150,7 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
 
   /**
    * Creates a loader.
-   * (Behavior when <code>instanceDir</code> is <code>null</code> is un-specified, in future versions this will fail due to NPE)
+   * @param instanceDir - base directory for this resource loader, must not be null
    */
   public SolrResourceLoader(Path instanceDir) {
     this(instanceDir, null);
@@ -170,20 +160,14 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL
    * This loader will delegate to Solr's classloader when possible,
    * otherwise it will attempt to resolve resources using any jar files
    * found in the "lib/" directory in the specified instance directory.
-   *
-   * @param instanceDir - base directory for this resource loader, if null locateSolrHome() will be used. (in future versions this will fail due to NPE)
-   * @see SolrPaths#locateSolrHome()
    */
   public SolrResourceLoader(Path instanceDir, ClassLoader parent) {
     if (instanceDir == null) {
-      log.warn("SolrResourceLoader created with null instanceDir.  This will not be supported in Solr 9.0");
-
-      this.instanceDir = SolrPaths.locateSolrHome();
-      log.debug("new SolrResourceLoader for deduced Solr Home: '{}'", this.instanceDir);
-    } else {
-      this.instanceDir = instanceDir;
-      log.debug("new SolrResourceLoader for directory: '{}'", this.instanceDir);
+      throw new NullPointerException("SolrResourceLoader instanceDir must be non-null");
     }
+    
+    this.instanceDir = instanceDir;
+    log.debug("new SolrResourceLoader for directory: '{}'", this.instanceDir);
 
     if (parent == null) {
       parent = getClass().getClassLoader();
diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
index 156d967..0c983f1 100644
--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
@@ -16,6 +16,10 @@
  */
 package org.apache.solr.servlet;
 
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
 import javax.servlet.ReadListener;
@@ -73,7 +77,6 @@ import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.NodeConfig;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.core.SolrInfoBean;
-import org.apache.solr.core.SolrPaths;
 import org.apache.solr.core.SolrXmlConfig;
 import org.apache.solr.metrics.AltBufferPoolMetricSet;
 import org.apache.solr.metrics.MetricsMap;
@@ -289,11 +292,56 @@ public class SolrDispatchFilter extends BaseSolrFilter {
   }
 
   /**
-   * Returns the effective Solr Home to use for this node
+   * Returns the effective Solr Home to use for this node, based on looking up the value in this order:
+   * <ol>
+   * <li>attribute in the FilterConfig</li>
+   * <li>JNDI: via java:comp/env/solr/home</li>
+   * <li>The system property solr.solr.home</li>
+   * <li>Look in the current working directory for a solr/ directory</li>
+   * </ol>
+   * <p>
+   *
+   * @return the Solr home, absolute and normalized.
+   * @see #SOLRHOME_ATTRIBUTE
    */
   private static Path computeSolrHome(FilterConfig config) {
-    final String solrHome = (String) config.getServletContext().getAttribute(SOLRHOME_ATTRIBUTE);
-    return (solrHome == null ? SolrPaths.locateSolrHome() : Paths.get(solrHome));
+
+    // start with explicit check of servlet config...
+    String source = "servlet config: " + SOLRHOME_ATTRIBUTE;
+    String home = (String) config.getServletContext().getAttribute(SOLRHOME_ATTRIBUTE);
+
+    if (null == home) {
+      final String lookup = "java:comp/env/solr/home";
+      // Try JNDI
+      source = "JNDI: " + lookup;
+      try {
+        Context c = new InitialContext();
+        home = (String) c.lookup(lookup);
+      } catch (NoInitialContextException e) {
+        log.debug("JNDI not configured for solr (NoInitialContextEx)");
+      } catch (NamingException e) {
+        log.debug("No /solr/home in JNDI");
+      } catch (RuntimeException ex) {
+        log.warn("Odd RuntimeException while testing for JNDI: ", ex);
+      }
+    }
+
+    if (null == home) {
+      // Now try system property
+      final String prop = "solr.solr.home";
+      source = "system property: " + prop;
+      home = System.getProperty(prop);
+    }
+
+    if (null == home) {
+      // if all else fails, assume default dir
+      home = "solr/";
+      source = "defaulted to '" + home + "' ... could not find system property or JNDI";
+    }
+    final Path solrHome = Paths.get(home).toAbsolutePath().normalize();
+    log.info("Solr Home: {} (source: {})", solrHome, source);
+    
+    return solrHome;
   }
   
   /**