From 3c35c00cf96f88b0f13deab71ef30cd06124ce2f Mon Sep 17 00:00:00 2001 From: Jean-Daniel Cryans Date: Mon, 4 May 2009 18:30:49 +0000 Subject: [PATCH] HBASE-1279 Fix the way hostnames and IPs are handled git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@771387 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + conf/hbase-default.xml | 15 +++++++++++++++ .../org/apache/hadoop/hbase/HServerInfo.java | 19 +++++++++++++++++++ .../apache/hadoop/hbase/master/HMaster.java | 11 ++++++++--- .../hbase/regionserver/HRegionServer.java | 7 ++++++- src/webapps/master/master.jsp | 2 +- 6 files changed, 50 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 37483645333..428e5b6fc9a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -102,6 +102,7 @@ Release 0.20.0 - Unreleased HBASE-1347 HTable.incrementColumnValue does not take negative 'amount' (Evgeny Ryabitskiy via Stack) HBASE-1365 Typo in TableInputFormatBase.setInputColums (Jon Gray via Stack) + HBASE-1279 Fix the way hostnames and IPs are handled IMPROVEMENTS HBASE-1089 Add count of regions on filesystem to master UI; add percentage diff --git a/conf/hbase-default.xml b/conf/hbase-default.xml index 4bf253e5bde..959d762a9cc 100644 --- a/conf/hbase-default.xml +++ b/conf/hbase-default.xml @@ -218,6 +218,21 @@ unstable region servers caused by an OOME. + + hbase.regionserver.dns.interface + default + The name of the Network Interface from which a region server + should report its IP address. + + + + hbase.regionserver.dns.nameserver + default + The host name or IP address of the name server (DNS) + which a region server should use to determine the host name used by the + master for communication and display purposes. + + hbase.regionserver.globalMemcache.upperLimit 0.4 diff --git a/src/java/org/apache/hadoop/hbase/HServerInfo.java b/src/java/org/apache/hadoop/hbase/HServerInfo.java index ed625bcb358..e2b6e6636f4 100644 --- a/src/java/org/apache/hadoop/hbase/HServerInfo.java +++ b/src/java/org/apache/hadoop/hbase/HServerInfo.java @@ -39,6 +39,7 @@ public class HServerInfo implements WritableComparable { private HServerLoad load; private int infoPort; private transient volatile String serverName = null; + private String name; /** default constructor - used by Writable */ public HServerInfo() { @@ -134,6 +135,22 @@ public class HServerInfo implements WritableComparable { } return this.serverName; } + + /** + * Get the hostname of the server + * @return hostname + */ + public String getName() { + return name; + } + + /** + * Set the hostname of the server + * @param name hostname + */ + public void setName(String name) { + this.name = name; + } /** * @see java.lang.Object#toString() @@ -177,6 +194,7 @@ public class HServerInfo implements WritableComparable { this.startCode = in.readLong(); this.load.readFields(in); this.infoPort = in.readInt(); + this.name = in.readUTF(); } public void write(DataOutput out) throws IOException { @@ -184,6 +202,7 @@ public class HServerInfo implements WritableComparable { out.writeLong(this.startCode); this.load.write(out); out.writeInt(this.infoPort); + out.writeUTF(name); } public int compareTo(HServerInfo o) { diff --git a/src/java/org/apache/hadoop/hbase/master/HMaster.java b/src/java/org/apache/hadoop/hbase/master/HMaster.java index 806b9b76186..040cf95e27a 100644 --- a/src/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/src/java/org/apache/hadoop/hbase/master/HMaster.java @@ -563,10 +563,15 @@ public class HMaster extends Thread implements HConstants, HMasterInterface, */ public MapWritable regionServerStartup(final HServerInfo serverInfo) throws IOException { - // Set the address for now even tho it will not be persisted on HRS side. - String rsAddress = HBaseServer.getRemoteAddress(); - serverInfo.setServerAddress(new HServerAddress(rsAddress, + // Set the address for now even tho it will not be persisted on HRS side + // If the address given is not the default one, + // use the IP given by the user. + if (serverInfo.getServerAddress().getBindAddress().equals( + DEFAULT_HOST)) { + String rsAddress = HBaseServer.getRemoteAddress(); + serverInfo.setServerAddress(new HServerAddress(rsAddress, serverInfo.getServerAddress().getPort())); + } // Register with server manager this.serverManager.regionServerStartup(serverInfo); // Send back some config info diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 36ec955a61b..5c7f9af84c0 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -101,6 +101,7 @@ import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper; import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.Writable; +import org.apache.hadoop.net.DNS; import org.apache.hadoop.util.Progressable; import org.apache.hadoop.util.StringUtils; import org.apache.zookeeper.WatchedEvent; @@ -289,9 +290,13 @@ public class HRegionServer implements HConstants, HRegionInterface, // Address is givin a default IP for the moment. Will be changed after // calling the master. this.serverInfo = new HServerInfo(new HServerAddress( - new InetSocketAddress(DEFAULT_HOST, + new InetSocketAddress(address.getBindAddress(), this.server.getListenerAddress().getPort())), System.currentTimeMillis(), this.conf.getInt("hbase.regionserver.info.port", 60030)); + String machineName = DNS.getDefaultHost( + conf.get("hbase.regionserver.dns.interface","default"), + conf.get("hbase.regionserver.dns.nameserver","default")); + this.serverInfo.setName(machineName); if (this.serverInfo.getServerAddress() == null) { throw new NullPointerException("Server address cannot be null; " + "hbase-958 debugging"); diff --git a/src/webapps/master/master.jsp b/src/webapps/master/master.jsp index db2afe611e5..81f2a0903ba 100644 --- a/src/webapps/master/master.jsp +++ b/src/webapps/master/master.jsp @@ -88,7 +88,7 @@ Arrays.sort(serverNames); for (String serverName: serverNames) { HServerInfo hsi = serverToServerInfos.get(serverName); - String hostname = hsi.getServerAddress().getHostname() + ":" + hsi.getInfoPort(); + String hostname = hsi.getName() + ":" + hsi.getInfoPort(); String url = "http://" + hostname + "/"; totalRegions += hsi.getLoad().getNumberOfRegions(); totalRequests += hsi.getLoad().getNumberOfRequests() / interval;