HBASE-14431 AsyncRpcClient#removeConnection() never removes connection from connections pool if server fails (Samir Ahmic)

This commit is contained in:
tedyu 2015-09-19 07:33:26 -07:00
parent 00f467b225
commit 88adccd553
2 changed files with 17 additions and 2 deletions

View File

@ -713,6 +713,21 @@ public class AsyncRpcChannel {
return ConnectionId.hashCode(ticket, serviceName, address); return ConnectionId.hashCode(ticket, serviceName, address);
} }
@Override
public int hashCode() {
return getConnectionHashCode();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof AsyncRpcChannel) {
AsyncRpcChannel channel = (AsyncRpcChannel) obj;
return channel.hashCode() == obj.hashCode();
}
return false;
}
@Override @Override
public String toString() { public String toString() {
return this.address.toString() + "/" + this.serviceName + "/" + this.ticket; return this.address.toString() + "/" + this.serviceName + "/" + this.ticket;

View File

@ -398,12 +398,12 @@ public class AsyncRpcClient extends AbstractRpcClient {
* Remove connection from pool * Remove connection from pool
*/ */
public void removeConnection(AsyncRpcChannel connection) { public void removeConnection(AsyncRpcChannel connection) {
int connectionHashCode = connection.getConnectionHashCode(); int connectionHashCode = connection.hashCode();
synchronized (connections) { synchronized (connections) {
// we use address as cache key, so we should check here to prevent removing the // we use address as cache key, so we should check here to prevent removing the
// wrong connection // wrong connection
AsyncRpcChannel connectionInPool = this.connections.get(connectionHashCode); AsyncRpcChannel connectionInPool = this.connections.get(connectionHashCode);
if (connectionInPool == connection) { if (connectionInPool.equals(connection)) {
this.connections.remove(connectionHashCode); this.connections.remove(connectionHashCode);
} else if (LOG.isDebugEnabled()) { } else if (LOG.isDebugEnabled()) {
LOG.debug(String.format("%s already removed, expected instance %08x, actual %08x", LOG.debug(String.format("%s already removed, expected instance %08x, actual %08x",