You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2016/12/13 20:30:27 UTC
[20/42] lucene-solr:feature/metrics: 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
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/8b98b158
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/8b98b158
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/8b98b158
Branch: refs/heads/feature/metrics
Commit: 8b98b158ff9cc2a71216e12c894ca14352d31f0e
Parents: c164f7e
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:03 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/8b98b158/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4f7377c..14dd2fa 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -152,6 +152,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/8b98b158/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);
+
}
}