From 1e90b73574ccde018d65671f979de101f0c8a46c Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Thu, 7 Jul 2011 16:44:49 +0000 Subject: [PATCH] HBASE-4074 When a RS has hostname with uppercase letter, there are two RS entries in master git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1143915 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../apache/hadoop/hbase/HServerAddress.java | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 96e8da94097..eb157ce49d7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -154,6 +154,8 @@ Release 0.91.0 - Unreleased HBASE-4061 getTableDirs is missing directories to skip HBASE-3867 when cluster is stopped and server which hosted meta region is removed from cluster, master breaks down after restarting cluster. + HBASE-4074 When a RS has hostname with uppercase letter, there are two + RS entries in master (Weihua via Ted Yu) IMPROVEMENTS HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack) diff --git a/src/main/java/org/apache/hadoop/hbase/HServerAddress.java b/src/main/java/org/apache/hadoop/hbase/HServerAddress.java index 166fa57f62c..94977e0e883 100644 --- a/src/main/java/org/apache/hadoop/hbase/HServerAddress.java +++ b/src/main/java/org/apache/hadoop/hbase/HServerAddress.java @@ -72,7 +72,7 @@ public class HServerAddress implements WritableComparable { * @param port Port number */ public HServerAddress(final String hostname, final int port) { - this(new InetSocketAddress(hostname, port)); + this(getResolvedAddress(new InetSocketAddress(hostname, port))); } /** @@ -80,21 +80,33 @@ public class HServerAddress implements WritableComparable { * @param other HServerAddress to copy from */ public HServerAddress(HServerAddress other) { - this(new InetSocketAddress(other.getHostname(), other.getPort())); + this(getResolvedAddress(new InetSocketAddress(other.getHostname(), other.getPort()))); } + private static InetSocketAddress getResolvedAddress(InetSocketAddress address) { + String bindAddress = getBindAddressInternal(address); + int port = address.getPort(); + return new InetSocketAddress(bindAddress, port); + } + /** @return Bind address -- the raw IP, the result of a call to * {@link InetSocketAddress#getAddress()#getHostAddress()} -- * or null if cannot resolve */ public String getBindAddress() { - // This returns null if the address is not resolved. - final InetAddress addr = this.address.getAddress(); - if (addr != null) return addr.getHostAddress(); - LogFactory.getLog(HServerAddress.class).error("Could not resolve the" - + " DNS name of " + this.address.toString()); - return null; + return getBindAddressInternal(address); } + private static String getBindAddressInternal(InetSocketAddress address) { + final InetAddress addr = address.getAddress(); + if (addr != null) { + return addr.getHostAddress(); + } else { + LogFactory.getLog(HServerAddress.class).error("Could not resolve the" + + " DNS name of " + address.getHostName()); + return null; + } + } + private void checkBindAddressCanBeResolved() { if (getBindAddress() == null) { throw new IllegalArgumentException("Could not resolve the" @@ -155,7 +167,7 @@ public class HServerAddress implements WritableComparable { String hostname = in.readUTF(); int port = in.readInt(); if (hostname != null && hostname.length() > 0) { - this.address = new InetSocketAddress(hostname, port); + this.address = getResolvedAddress(new InetSocketAddress(hostname, port)); checkBindAddressCanBeResolved(); createCachedToString(); } @@ -182,4 +194,4 @@ public class HServerAddress implements WritableComparable { if (this.address.equals(o.address)) return 0; return toString().compareTo(o.toString()); } -} \ No newline at end of file +}