hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajeshb...@apache.org
Subject git commit: HBASE-10200 Better error message when HttpServer fails to start due to java.net.BindException(Kiran Kumar M R)
Date Tue, 14 Oct 2014 02:26:32 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 8828e0a68 -> a6dbddacf


HBASE-10200 Better error message when HttpServer fails to start due to java.net.BindException(Kiran
Kumar M R)


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

Branch: refs/heads/branch-1
Commit: a6dbddacfb9bfcba7ee4a35cc5801c0fc0dcdbc6
Parents: 8828e0a
Author: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Authored: Tue Oct 14 02:26:13 2014 +0000
Committer: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Committed: Tue Oct 14 02:26:13 2014 +0000

----------------------------------------------------------------------
 .../apache/hadoop/hbase/util/Addressing.java    | 21 ++++++++++++++++++++
 .../org/apache/hadoop/hbase/master/HMaster.java | 12 ++++++++++-
 .../hbase/regionserver/HRegionServer.java       | 10 ++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/a6dbddac/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java
index 8fb554f..a7c929f 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java
@@ -102,4 +102,25 @@ public class Addressing {
 
     throw new SocketException("Can't get our ip address, interfaces are: " + interfaces);
   }
+
+  /**
+   * Given an InetAddress, checks to see if the address is a local address, by comparing
the address
+   * with all the interfaces on the node.
+   * @param addr address to check if it is local node's address
+   * @return true if the address corresponds to the local node
+   */
+  public static boolean isLocalAddress(InetAddress addr) {
+    // Check if the address is any local or loop back
+    boolean local = addr.isAnyLocalAddress() || addr.isLoopbackAddress();
+
+    // Check if the address is defined on any interface
+    if (!local) {
+      try {
+        local = NetworkInterface.getByInetAddress(addr) != null;
+      } catch (SocketException e) {
+        local = false;
+      }
+    }
+    return local;
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/a6dbddac/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
index 0dedddd..41a748f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
@@ -109,6 +109,7 @@ import org.apache.hadoop.hbase.regionserver.RSRpcServices;
 import org.apache.hadoop.hbase.regionserver.RegionSplitPolicy;
 import org.apache.hadoop.hbase.replication.regionserver.Replication;
 import org.apache.hadoop.hbase.security.UserProvider;
+import org.apache.hadoop.hbase.util.Addressing;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.CompressionTest;
 import org.apache.hadoop.hbase.util.FSUtils;
@@ -316,11 +317,20 @@ public class HMaster extends HRegionServer implements MasterServices,
Server {
     if (infoPort < 0 || infoServer == null) {
       return;
     }
+    String addr = conf.get("hbase.master.info.bindAddress", "0.0.0.0");
+    if (!Addressing.isLocalAddress(InetAddress.getByName(addr))) {
+      String msg =
+          "Failed to start redirecting jetty server. Address " + addr
+              + " does not belong to this host. Correct configuration parameter: "
+              + "hbase.master.info.bindAddress";
+      LOG.error(msg);
+      throw new IOException(msg);
+    }
 
     RedirectServlet.regionServerInfoPort = infoServer.getPort();
     masterJettyServer = new org.mortbay.jetty.Server();
     Connector connector = new SelectChannelConnector();
-    connector.setHost(conf.get("hbase.master.info.bindAddress", "0.0.0.0"));
+    connector.setHost(addr);
     connector.setPort(infoPort);
     masterJettyServer.addConnector(connector);
     masterJettyServer.setStopAtShutdown(true);

http://git-wip-us.apache.org/repos/asf/hbase/blob/a6dbddac/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
index 645e016..6e08b6f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
@@ -45,6 +45,7 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ConcurrentSkipListMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.net.InetAddress;
 
 import javax.management.ObjectName;
 import javax.servlet.http.HttpServlet;
@@ -127,6 +128,7 @@ import org.apache.hadoop.hbase.regionserver.wal.HLogUtil;
 import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
 import org.apache.hadoop.hbase.security.UserProvider;
 import org.apache.hadoop.hbase.trace.SpanReceiverHost;
+import org.apache.hadoop.hbase.util.Addressing;
 import org.apache.hadoop.hbase.util.ByteStringer;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.CompressionTest;
@@ -1646,6 +1648,14 @@ public class HRegionServer extends HasThread implements
     // -1 is for disabling info server
     if (port < 0) return port;
     String addr = this.conf.get("hbase.regionserver.info.bindAddress", "0.0.0.0");
+    if (!Addressing.isLocalAddress(InetAddress.getByName(addr))) {
+      String msg =
+          "Failed to start http info server. Address " + addr
+              + " does not belong to this host. Correct configuration parameter: "
+              + "hbase.regionserver.info.bindAddress";
+      LOG.error(msg);
+      throw new IOException(msg);
+    }
     // check if auto port bind enabled
     boolean auto = this.conf.getBoolean(HConstants.REGIONSERVER_INFO_PORT_AUTO,
         false);


Mime
View raw message