HBASE-2031 When starting HQuorumPeer, try to match on more than 1 address
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@889461 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0db51718ce
commit
5d8688fc3d
|
@ -224,6 +224,7 @@ Release 0.21.0 - Unreleased
|
||||||
(Dave Latham via Stack)
|
(Dave Latham via Stack)
|
||||||
HBASE-2013 Add useful helpers to HBaseTestingUtility.java (Lars George
|
HBASE-2013 Add useful helpers to HBaseTestingUtility.java (Lars George
|
||||||
via J-D)
|
via J-D)
|
||||||
|
HBASE-2031 When starting HQuorumPeer, try to match on more than 1 address
|
||||||
|
|
||||||
NEW FEATURES
|
NEW FEATURES
|
||||||
HBASE-1901 "General" partitioner for "hbase-48" bulk (behind the api, write
|
HBASE-1901 "General" partitioner for "hbase-48" bulk (behind the api, write
|
||||||
|
|
|
@ -24,7 +24,12 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -90,22 +95,32 @@ public class HQuorumPeer implements HConstants {
|
||||||
return address.equals("localhost") || address.equals("127.0.0.1");
|
return address.equals("localhost") || address.equals("127.0.0.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hostEquals(String addrA, String addrB) {
|
private static void writeMyID(Properties properties) throws IOException {
|
||||||
if (addrA.contains(".") && addrB.contains(".")) {
|
long myId = -1;
|
||||||
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 UnknownHostException, IOException {
|
|
||||||
HBaseConfiguration conf = new HBaseConfiguration();
|
HBaseConfiguration conf = new HBaseConfiguration();
|
||||||
String myAddress = DNS.getDefaultHost(
|
String myAddress = DNS.getDefaultHost(
|
||||||
conf.get("hbase.zookeeper.dns.interface","default"),
|
conf.get("hbase.zookeeper.dns.interface","default"),
|
||||||
conf.get("hbase.zookeeper.dns.nameserver","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()) {
|
for (Entry<Object, Object> entry : properties.entrySet()) {
|
||||||
String key = entry.getKey().toString().trim();
|
String key = entry.getKey().toString().trim();
|
||||||
|
@ -115,9 +130,7 @@ public class HQuorumPeer implements HConstants {
|
||||||
long id = Long.parseLong(key.substring(dot + 1));
|
long id = Long.parseLong(key.substring(dot + 1));
|
||||||
String[] parts = value.split(":");
|
String[] parts = value.split(":");
|
||||||
String address = parts[0];
|
String address = parts[0];
|
||||||
if (addressIsLocalHost(address) || hostEquals(myAddress, address)) {
|
if (addressIsLocalHost(address) || ips.contains(address)) {
|
||||||
LOG.debug("found my address: " + myAddress + ", in list: " + address +
|
|
||||||
", setting myId to " + id);
|
|
||||||
myId = id;
|
myId = id;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue