You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2010/07/05 19:47:11 UTC
svn commit: r960650 - in /hbase/trunk: CHANGES.txt
src/main/java/org/apache/hadoop/hbase/HServerAddress.java
Author: stack
Date: Mon Jul 5 17:47:10 2010
New Revision: 960650
URL: http://svn.apache.org/viewvc?rev=960650&view=rev
Log:
HBASE-2806 DNS hiccups cause uncaught NPE in HServerAddress#getBindAddress
Modified:
hbase/trunk/CHANGES.txt
hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerAddress.java
Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=960650&r1=960649&r2=960650&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Mon Jul 5 17:47:10 2010
@@ -426,6 +426,8 @@ Release 0.21.0 - Unreleased
HBASE-2707 Can't recover from a dead ROOT server if any exceptions happens
during log splitting
HBASE-2501 Refactor StoreFile Code
+ HBASE-2806 DNS hiccups cause uncaught NPE in HServerAddress#getBindAddress
+ (Benoit Sigoure via Stack)
IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerAddress.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerAddress.java?rev=960650&r1=960649&r2=960650&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerAddress.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/HServerAddress.java Mon Jul 5 17:47:10 2010
@@ -19,12 +19,14 @@
*/
package org.apache.hadoop.hbase;
-import org.apache.hadoop.io.*;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.io.WritableComparable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.net.InetAddress;
/**
* HServerAddress is a "label" for a HBase server made of host and port number.
@@ -39,13 +41,14 @@ public class HServerAddress implements W
}
/**
- * Construct a HServerAddress from an InetSocketAddress
+ * Construct an instance from an {@link InetSocketAddress}.
* @param address InetSocketAddress of server
*/
public HServerAddress(InetSocketAddress address) {
this.address = address;
this.stringValue = address.getAddress().getHostAddress() + ":" +
address.getPort();
+ checkBindAddressCanBeResolved();
}
/**
@@ -53,14 +56,14 @@ public class HServerAddress implements W
*/
public HServerAddress(String hostAndPort) {
int colonIndex = hostAndPort.lastIndexOf(':');
- if(colonIndex < 0) {
+ if (colonIndex < 0) {
throw new IllegalArgumentException("Not a host:port pair: " + hostAndPort);
}
String host = hostAndPort.substring(0, colonIndex);
- int port =
- Integer.valueOf(hostAndPort.substring(colonIndex + 1)).intValue();
+ int port = Integer.parseInt(hostAndPort.substring(colonIndex + 1));
this.address = new InetSocketAddress(host, port);
this.stringValue = hostAndPort;
+ checkBindAddressCanBeResolved();
}
/**
@@ -70,38 +73,53 @@ public class HServerAddress implements W
public HServerAddress(String bindAddress, int port) {
this.address = new InetSocketAddress(bindAddress, port);
this.stringValue = bindAddress + ":" + port;
+ checkBindAddressCanBeResolved();
}
/**
- * Copy-constructor
- *
+ * Copy-constructor.
* @param other HServerAddress to copy from
*/
public HServerAddress(HServerAddress other) {
String bindAddress = other.getBindAddress();
int port = other.getPort();
this.address = new InetSocketAddress(bindAddress, port);
- stringValue = bindAddress + ":" + port;
+ stringValue = other.stringValue;
+ checkBindAddressCanBeResolved();
}
/** @return Bind address */
public String getBindAddress() {
- return this.address.getAddress().getHostAddress();
+ final InetAddress addr = address.getAddress();
+ if (addr != null) {
+ return addr.getHostAddress();
+ } else {
+ LogFactory.getLog(HServerAddress.class).error("Could not resolve the"
+ + " DNS name of " + stringValue);
+ return null;
+ }
+ }
+
+ private checkBindAddressCanBeResolved() {
+ if (getBindAddress() == null) {
+ throw new IllegalArgumentException("Could not resolve the"
+ + " DNS name of " + stringValue);
+ }
}
/** @return Port number */
public int getPort() {
- return this.address.getPort();
+ return address.getPort();
}
/** @return Hostname */
public String getHostname() {
- return this.address.getHostName();
+ return address.getHostName();
}
/** @return The InetSocketAddress */
public InetSocketAddress getInetSocketAddress() {
- return this.address;
+ return address;
}
/**
@@ -109,7 +127,7 @@ public class HServerAddress implements W
*/
@Override
public String toString() {
- return (this.stringValue == null ? "" : this.stringValue);
+ return stringValue == null ? "" : stringValue;
}
@Override
@@ -123,13 +141,13 @@ public class HServerAddress implements W
if (getClass() != o.getClass()) {
return false;
}
- return this.compareTo((HServerAddress)o) == 0;
+ return compareTo((HServerAddress) o) == 0;
}
@Override
public int hashCode() {
- int result = this.address.hashCode();
- result ^= this.stringValue.hashCode();
+ int result = address.hashCode();
+ result ^= stringValue.hashCode();
return result;
}
@@ -141,13 +159,13 @@ public class HServerAddress implements W
String bindAddress = in.readUTF();
int port = in.readInt();
- if(bindAddress == null || bindAddress.length() == 0) {
+ if (bindAddress == null || bindAddress.length() == 0) {
address = null;
stringValue = null;
-
} else {
address = new InetSocketAddress(bindAddress, port);
stringValue = bindAddress + ":" + port;
+ checkBindAddressCanBeResolved();
}
}
@@ -155,7 +173,6 @@ public class HServerAddress implements W
if (address == null) {
out.writeUTF("");
out.writeInt(0);
-
} else {
out.writeUTF(address.getAddress().getHostAddress());
out.writeInt(address.getPort());
@@ -170,7 +187,7 @@ public class HServerAddress implements W
// Addresses as Strings may not compare though address is for the one
// server with only difference being that one address has hostname
// resolved whereas other only has IP.
- if (this.address.equals(o.address)) return 0;
- return this.toString().compareTo(o.toString());
+ if (address.equals(o.address)) return 0;
+ return toString().compareTo(o.toString());
}
-}
\ No newline at end of file
+}