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 2016/12/06 21:49:51 UTC

[2/2] lucene-solr:branch_6x: SOLR-5043: New solr.dns.prevent.reverse.lookup system property that can be used to prevent long core (re)load delays on systems with missconfigured hostname/DNS

SOLR-5043: New solr.dns.prevent.reverse.lookup system property that can be used to prevent long core (re)load delays on systems with missconfigured hostname/DNS

(cherry picked from commit 8b98b158ff9cc2a71216e12c894ca14352d31f0e)


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

Branch: refs/heads/branch_6x
Commit: 135604f6327032d0258227aaa524369203d40822
Parents: fdec787
Author: Chris Hostetter <ho...@apache.org>
Authored: Tue Dec 6 14:47:03 2016 -0700
Committer: Chris Hostetter <ho...@apache.org>
Committed: Tue Dec 6 14:47:21 2016 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 ++
 .../solr/handler/admin/SystemInfoHandler.java   | 51 +++++++++++++++++---
 2 files changed, 46 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/135604f6/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 033e879..8eb620b 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -98,6 +98,9 @@ New Features
 
 * SOLR-9728: Ability to specify Key Store type in solr.in.sh file for SSL (Michael Suzuki, Kevin Risden)
 
+* SOLR-5043: New solr.dns.prevent.reverse.lookup system property that can be used to prevent long core
+  (re)load delays on systems with missconfigured hostname/DNS (hossman)
+
 Optimizations
 ----------------------
 * SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that have

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/135604f6/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
index 35ef906..a873c09 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
@@ -31,7 +31,6 @@ import java.lang.management.PlatformManagedObject;
 import java.lang.management.RuntimeMXBean;
 import java.lang.reflect.InvocationTargetException;
 import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.nio.charset.Charset;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
@@ -50,6 +49,8 @@ import org.apache.solr.handler.RequestHandlerBase;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.response.SolrQueryResponse;
 import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.util.RTimer;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -64,8 +65,22 @@ import static org.apache.solr.common.params.CommonParams.NAME;
 public class SystemInfoHandler extends RequestHandlerBase 
 {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-  
 
+  /**
+   * <p>
+   * Undocumented expert level system property to prevent doing a reverse lookup of our hostname.
+   * This property ill be logged as a suggested workaround if any probems are noticed when doing reverse 
+   * lookup.
+   * </p>
+   *
+   * <p>
+   * TODO: should we refactor this (and the associated logic) into a helper method for any other places
+   * where DNS is used?
+   * </p>
+   * @see #initHostname
+   */
+  private static final String PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP = "solr.dns.prevent.reverse.lookup";
+  
   // on some platforms, resolving canonical hostname can cause the thread
   // to block for several seconds if nameservices aren't available
   // so resolve this once per handler instance 
@@ -75,22 +90,42 @@ public class SystemInfoHandler extends RequestHandlerBase
   private CoreContainer cc;
 
   public SystemInfoHandler() {
-    super();
-    init();
+    this(null);
   }
 
   public SystemInfoHandler(CoreContainer cc) {
     super();
     this.cc = cc;
-    init();
+    initHostname();
   }
   
-  private void init() {
+  private void initHostname() {
+    if (null != System.getProperty(PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP, null)) {
+      log.info("Resolving canonical hostname for local host prevented due to '{}' sysprop",
+               PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP);
+      hostname = null;
+      return;
+    }
+    
+    RTimer timer = new RTimer();
     try {
       InetAddress addr = InetAddress.getLocalHost();
       hostname = addr.getCanonicalHostName();
-    } catch (UnknownHostException e) {
-      //default to null
+    } catch (Exception e) {
+      log.warn("Unable to resolve canonical hostname for local host, possible DNS misconfiguration. " +
+               "Set the '"+PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP+"' sysprop to true on startup to " +
+               "prevent future lookups if DNS can not be fixed.", e);
+      hostname = null;
+      return;
+    }
+    timer.stop();
+    
+    if (15000D < timer.getTime()) {
+      String readableTime = String.format(Locale.ROOT, "%.3f", (timer.getTime() / 1000));
+      log.warn("Resolving canonical hostname for local host took {} seconds, possible DNS misconfiguration. " +
+               "Set the '{}' sysprop to true on startup to prevent future lookups if DNS can not be fixed.",
+               readableTime, PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP);
+    
     }
   }