HBASE-2806 DNS hiccups cause uncaught NPE in HServerAddress#getBindAddress
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@960650 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
03933720fa
commit
2993d97c97
@ -426,6 +426,8 @@ Release 0.21.0 - Unreleased
|
|||||||
HBASE-2707 Can't recover from a dead ROOT server if any exceptions happens
|
HBASE-2707 Can't recover from a dead ROOT server if any exceptions happens
|
||||||
during log splitting
|
during log splitting
|
||||||
HBASE-2501 Refactor StoreFile Code
|
HBASE-2501 Refactor StoreFile Code
|
||||||
|
HBASE-2806 DNS hiccups cause uncaught NPE in HServerAddress#getBindAddress
|
||||||
|
(Benoit Sigoure via Stack)
|
||||||
|
|
||||||
IMPROVEMENTS
|
IMPROVEMENTS
|
||||||
HBASE-1760 Cleanup TODOs in HTable
|
HBASE-1760 Cleanup TODOs in HTable
|
||||||
|
@ -19,12 +19,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase;
|
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.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HServerAddress is a "label" for a HBase server made of host and port number.
|
* HServerAddress is a "label" for a HBase server made of host and port number.
|
||||||
@ -39,13 +41,14 @@ public class HServerAddress implements WritableComparable<HServerAddress> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a HServerAddress from an InetSocketAddress
|
* Construct an instance from an {@link InetSocketAddress}.
|
||||||
* @param address InetSocketAddress of server
|
* @param address InetSocketAddress of server
|
||||||
*/
|
*/
|
||||||
public HServerAddress(InetSocketAddress address) {
|
public HServerAddress(InetSocketAddress address) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.stringValue = address.getAddress().getHostAddress() + ":" +
|
this.stringValue = address.getAddress().getHostAddress() + ":" +
|
||||||
address.getPort();
|
address.getPort();
|
||||||
|
checkBindAddressCanBeResolved();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,14 +56,14 @@ public class HServerAddress implements WritableComparable<HServerAddress> {
|
|||||||
*/
|
*/
|
||||||
public HServerAddress(String hostAndPort) {
|
public HServerAddress(String hostAndPort) {
|
||||||
int colonIndex = hostAndPort.lastIndexOf(':');
|
int colonIndex = hostAndPort.lastIndexOf(':');
|
||||||
if(colonIndex < 0) {
|
if (colonIndex < 0) {
|
||||||
throw new IllegalArgumentException("Not a host:port pair: " + hostAndPort);
|
throw new IllegalArgumentException("Not a host:port pair: " + hostAndPort);
|
||||||
}
|
}
|
||||||
String host = hostAndPort.substring(0, colonIndex);
|
String host = hostAndPort.substring(0, colonIndex);
|
||||||
int port =
|
int port = Integer.parseInt(hostAndPort.substring(colonIndex + 1));
|
||||||
Integer.valueOf(hostAndPort.substring(colonIndex + 1)).intValue();
|
|
||||||
this.address = new InetSocketAddress(host, port);
|
this.address = new InetSocketAddress(host, port);
|
||||||
this.stringValue = hostAndPort;
|
this.stringValue = hostAndPort;
|
||||||
|
checkBindAddressCanBeResolved();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,38 +73,53 @@ public class HServerAddress implements WritableComparable<HServerAddress> {
|
|||||||
public HServerAddress(String bindAddress, int port) {
|
public HServerAddress(String bindAddress, int port) {
|
||||||
this.address = new InetSocketAddress(bindAddress, port);
|
this.address = new InetSocketAddress(bindAddress, port);
|
||||||
this.stringValue = bindAddress + ":" + port;
|
this.stringValue = bindAddress + ":" + port;
|
||||||
|
checkBindAddressCanBeResolved();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy-constructor
|
* Copy-constructor.
|
||||||
*
|
|
||||||
* @param other HServerAddress to copy from
|
* @param other HServerAddress to copy from
|
||||||
*/
|
*/
|
||||||
public HServerAddress(HServerAddress other) {
|
public HServerAddress(HServerAddress other) {
|
||||||
String bindAddress = other.getBindAddress();
|
String bindAddress = other.getBindAddress();
|
||||||
int port = other.getPort();
|
int port = other.getPort();
|
||||||
this.address = new InetSocketAddress(bindAddress, port);
|
this.address = new InetSocketAddress(bindAddress, port);
|
||||||
stringValue = bindAddress + ":" + port;
|
stringValue = other.stringValue;
|
||||||
|
checkBindAddressCanBeResolved();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return Bind address */
|
/** @return Bind address */
|
||||||
public String getBindAddress() {
|
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 */
|
/** @return Port number */
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return this.address.getPort();
|
return address.getPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return Hostname */
|
/** @return Hostname */
|
||||||
public String getHostname() {
|
public String getHostname() {
|
||||||
return this.address.getHostName();
|
return address.getHostName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return The InetSocketAddress */
|
/** @return The InetSocketAddress */
|
||||||
public InetSocketAddress getInetSocketAddress() {
|
public InetSocketAddress getInetSocketAddress() {
|
||||||
return this.address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,7 +127,7 @@ public class HServerAddress implements WritableComparable<HServerAddress> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return (this.stringValue == null ? "" : this.stringValue);
|
return stringValue == null ? "" : stringValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -123,13 +141,13 @@ public class HServerAddress implements WritableComparable<HServerAddress> {
|
|||||||
if (getClass() != o.getClass()) {
|
if (getClass() != o.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.compareTo((HServerAddress)o) == 0;
|
return compareTo((HServerAddress) o) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = this.address.hashCode();
|
int result = address.hashCode();
|
||||||
result ^= this.stringValue.hashCode();
|
result ^= stringValue.hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,13 +159,13 @@ public class HServerAddress implements WritableComparable<HServerAddress> {
|
|||||||
String bindAddress = in.readUTF();
|
String bindAddress = in.readUTF();
|
||||||
int port = in.readInt();
|
int port = in.readInt();
|
||||||
|
|
||||||
if(bindAddress == null || bindAddress.length() == 0) {
|
if (bindAddress == null || bindAddress.length() == 0) {
|
||||||
address = null;
|
address = null;
|
||||||
stringValue = null;
|
stringValue = null;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
address = new InetSocketAddress(bindAddress, port);
|
address = new InetSocketAddress(bindAddress, port);
|
||||||
stringValue = bindAddress + ":" + port;
|
stringValue = bindAddress + ":" + port;
|
||||||
|
checkBindAddressCanBeResolved();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +173,6 @@ public class HServerAddress implements WritableComparable<HServerAddress> {
|
|||||||
if (address == null) {
|
if (address == null) {
|
||||||
out.writeUTF("");
|
out.writeUTF("");
|
||||||
out.writeInt(0);
|
out.writeInt(0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
out.writeUTF(address.getAddress().getHostAddress());
|
out.writeUTF(address.getAddress().getHostAddress());
|
||||||
out.writeInt(address.getPort());
|
out.writeInt(address.getPort());
|
||||||
@ -170,7 +187,7 @@ public class HServerAddress implements WritableComparable<HServerAddress> {
|
|||||||
// Addresses as Strings may not compare though address is for the one
|
// Addresses as Strings may not compare though address is for the one
|
||||||
// server with only difference being that one address has hostname
|
// server with only difference being that one address has hostname
|
||||||
// resolved whereas other only has IP.
|
// resolved whereas other only has IP.
|
||||||
if (this.address.equals(o.address)) return 0;
|
if (address.equals(o.address)) return 0;
|
||||||
return this.toString().compareTo(o.toString());
|
return toString().compareTo(o.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user