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:24:47 UTC

svn commit: r889462 - in /hadoop/hbase/branches/0.20: CHANGES.txt src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java

Author: jdcryans
Date: Thu Dec 10 23:24:47 2009
New Revision: 889462

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

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

Modified: hadoop/hbase/branches/0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/CHANGES.txt?rev=889462&r1=889461&r2=889462&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/CHANGES.txt (original)
+++ hadoop/hbase/branches/0.20/CHANGES.txt Thu Dec 10 23:24:47 2009
@@ -30,8 +30,9 @@
    HBASE-2018  Updates to .META. blocked under high MemStore load
    HBASE-2029  Reduce shell exception dump on console
                (Lars George and J-D via Stack)
-   HBASE-2027 HConnectionManager.HBASE_INSTANCES leaks TableServers
-              (Dave Latham via Stack)
+   HBASE-2027  HConnectionManager.HBASE_INSTANCES leaks TableServers
+               (Dave Latham via Stack)
+   HBASE-2031  When starting HQuorumPeer, try to match on more than 1 address
 
 Release 0.20.2 - November 18th, 2009
   INCOMPATIBLE CHANGES

Modified: hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java?rev=889462&r1=889461&r2=889462&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java (original)
+++ hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java Thu Dec 10 23:24:47 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;
         }