You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by jd...@apache.org on 2009/12/11 00:17:35 UTC

svn commit: r889461 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java

Author: jdcryans
Date: Thu Dec 10 23:17:35 2009
New Revision: 889461

URL: http://svn.apache.org/viewvc?rev=889461&view=rev
Log:
HBASE-2031 When starting HQuorumPeer, try to match on more than 1 address

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=889461&r1=889460&r2=889461&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Dec 10 23:17:35 2009
@@ -224,6 +224,7 @@
                (Dave Latham via Stack)
    HBASE-2013  Add useful helpers to HBaseTestingUtility.java (Lars George
                via J-D)
+   HBASE-2031  When starting HQuorumPeer, try to match on more than 1 address
 
   NEW FEATURES
    HBASE-1901  "General" partitioner for "hbase-48" bulk (behind the api, write

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java?rev=889461&r1=889460&r2=889461&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java Thu Dec 10 23:17:35 2009
@@ -24,7 +24,12 @@
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.net.UnknownHostException;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
 import java.util.Properties;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.Map.Entry;
 
 import org.apache.commons.logging.Log;
@@ -90,22 +95,32 @@
     return address.equals("localhost") || address.equals("127.0.0.1");
   }
 
-  private static boolean hostEquals(String addrA, String addrB) {
-    if (addrA.contains(".") && addrB.contains(".")) {
-      return addrA.equals(addrB);
-    }
-    String hostA = StringUtils.simpleHostname(addrA);
-    String hostB = StringUtils.simpleHostname(addrB);
-    return hostA.equals(hostB);
-  }
+  private static void writeMyID(Properties properties) throws IOException {
+    long myId = -1;
 
-  private static void writeMyID(Properties properties) throws UnknownHostException, IOException {
     HBaseConfiguration conf = new HBaseConfiguration();
     String myAddress = DNS.getDefaultHost(
         conf.get("hbase.zookeeper.dns.interface","default"),
         conf.get("hbase.zookeeper.dns.nameserver","default"));
 
-    long myId = -1;
+    List<String> ips = new ArrayList<String>();
+
+    // Add what could be the best (configured) match
+    ips.add(myAddress.contains(".") ?
+        myAddress :
+        StringUtils.simpleHostname(myAddress));
+
+    // For all nics get all hostnames and IPs
+    Enumeration<?> nics = NetworkInterface.getNetworkInterfaces();
+    while(nics.hasMoreElements()) {
+      Enumeration<?> rawAdrs =
+          ((NetworkInterface)nics.nextElement()).getInetAddresses();
+      while(rawAdrs.hasMoreElements()) {
+        InetAddress inet = (InetAddress) rawAdrs.nextElement();
+        ips.add(StringUtils.simpleHostname(inet.getHostName()));
+        ips.add(inet.getHostAddress());
+      }
+    }
 
     for (Entry<Object, Object> entry : properties.entrySet()) {
       String key = entry.getKey().toString().trim();
@@ -115,9 +130,7 @@
         long id = Long.parseLong(key.substring(dot + 1));
         String[] parts = value.split(":");
         String address = parts[0];
-        if (addressIsLocalHost(address) || hostEquals(myAddress, address)) {
-          LOG.debug("found my address: " + myAddress + ", in list: " + address +
-                    ", setting myId to " + id);
+        if (addressIsLocalHost(address) || ips.contains(address)) {
           myId = id;
           break;
         }