hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject hbase git commit: HBASE-12742
Date Tue, 23 Dec 2014 18:17:43 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.0 0d688a5a0 -> d702dbe59


HBASE-12742

Signed-off-by: stack <stack@apache.org>


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

Branch: refs/heads/branch-1.0
Commit: d702dbe59eddf15011a5a4c4da2f46a72f82bb9d
Parents: 0d688a5
Author: Jurriaan Mous <jurmous@jurmo.us>
Authored: Mon Dec 22 17:35:19 2014 +0100
Committer: stack <stack@apache.org>
Committed: Tue Dec 23 10:17:22 2014 -0800

----------------------------------------------------------------------
 .../apache/hadoop/hbase/util/Addressing.java    | 42 +++++++++++++++++++-
 .../hbase/master/ClusterStatusPublisher.java    | 12 ++++--
 2 files changed, 49 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/d702dbe5/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 a7c929f..fce0d40 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
@@ -83,6 +83,34 @@ public class Addressing {
   }
 
   public static InetAddress getIpAddress() throws SocketException {
+    return getIpAddress(new AddressSelectionCondition() {
+      @Override
+      public boolean isAcceptableAddress(InetAddress addr) {
+        return addr instanceof Inet4Address || addr instanceof Inet6Address;
+      }
+    });
+  }
+
+  public static InetAddress getIp4Address() throws SocketException {
+    return getIpAddress(new AddressSelectionCondition() {
+      @Override
+      public boolean isAcceptableAddress(InetAddress addr) {
+        return addr instanceof Inet4Address;
+      }
+    });
+  }
+
+  public static InetAddress getIp6Address() throws SocketException {
+    return getIpAddress(new AddressSelectionCondition() {
+      @Override
+      public boolean isAcceptableAddress(InetAddress addr) {
+        return addr instanceof Inet6Address;
+      }
+    });
+  }
+
+  private static InetAddress getIpAddress(AddressSelectionCondition condition) throws
+      SocketException {
     // Before we connect somewhere, we cannot be sure about what we'd be bound to; however,
     // we only connect when the message where client ID is, is long constructed. Thus,
     // just use whichever IP address we can find.
@@ -94,7 +122,7 @@ public class Addressing {
       while (addresses.hasMoreElements()) {
         InetAddress addr = addresses.nextElement();
         if (addr.isLoopbackAddress()) continue;
-        if (addr instanceof Inet4Address || addr instanceof Inet6Address) {
+        if (condition.isAcceptableAddress(addr)) {
           return addr;
         }
       }
@@ -123,4 +151,16 @@ public class Addressing {
     }
     return local;
   }
+
+  /**
+   * Interface for AddressSelectionCondition to check if address is acceptable
+   */
+  public interface AddressSelectionCondition{
+    /**
+     * Condition on which to accept inet address
+     * @param address to check
+     * @return true to accept this address
+     */
+    public boolean isAcceptableAddress(InetAddress address);
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/d702dbe5/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterStatusPublisher.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterStatusPublisher.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterStatusPublisher.java
index 5fffcaa..6e7024c 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterStatusPublisher.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ClusterStatusPublisher.java
@@ -253,8 +253,6 @@ public class ClusterStatusPublisher extends Chore {
 
     @Override
     public void connect(Configuration conf) throws IOException {
-      NetworkInterface ni = NetworkInterface.getByInetAddress(Addressing.getIpAddress());
-
       String mcAddress = conf.get(HConstants.STATUS_MULTICAST_ADDRESS,
           HConstants.DEFAULT_STATUS_MULTICAST_ADDRESS);
       int port = conf.getInt(HConstants.STATUS_MULTICAST_PORT,
@@ -269,13 +267,19 @@ public class ClusterStatusPublisher extends Chore {
       }
 
       final InetSocketAddress isa = new InetSocketAddress(mcAddress, port);
-      InternetProtocolFamily family = InternetProtocolFamily.IPv4;
+
+      InternetProtocolFamily family;
+      InetAddress localAddress;
       if (ina instanceof Inet6Address) {
+        localAddress = Addressing.getIp6Address();
         family = InternetProtocolFamily.IPv6;
+      }else{
+        localAddress = Addressing.getIp4Address();
+        family = InternetProtocolFamily.IPv4;
       }
+      NetworkInterface ni = NetworkInterface.getByInetAddress(localAddress);
 
       Bootstrap b = new Bootstrap();
-
       b.group(group)
       .channelFactory(new HBaseDatagramChannelFactory<Channel>(NioDatagramChannel.class,
family))
       .option(ChannelOption.SO_REUSEADDR, true)


Mime
View raw message