HADOOP-19218 Avoid DNS lookup while creating IPC Connection object (#6916). Contributed by Viraj Jasani.
Signed-off-by: Rushabh Shah <shahrs87@apache.org> Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
This commit is contained in:
parent
5730656660
commit
1360c7574a
@ -2034,10 +2034,6 @@ public class Connection {
|
|||||||
* Address to which the socket is connected to.
|
* Address to which the socket is connected to.
|
||||||
*/
|
*/
|
||||||
private final InetAddress addr;
|
private final InetAddress addr;
|
||||||
/**
|
|
||||||
* Client Host address from where the socket connection is being established to the Server.
|
|
||||||
*/
|
|
||||||
private final String hostName;
|
|
||||||
|
|
||||||
IpcConnectionContextProto connectionContext;
|
IpcConnectionContextProto connectionContext;
|
||||||
String protocolName;
|
String protocolName;
|
||||||
@ -2081,12 +2077,9 @@ public Connection(SocketChannel channel, long lastContact,
|
|||||||
this.isOnAuxiliaryPort = isOnAuxiliaryPort;
|
this.isOnAuxiliaryPort = isOnAuxiliaryPort;
|
||||||
if (addr == null) {
|
if (addr == null) {
|
||||||
this.hostAddress = "*Unknown*";
|
this.hostAddress = "*Unknown*";
|
||||||
this.hostName = this.hostAddress;
|
|
||||||
} else {
|
} else {
|
||||||
// host IP address
|
// host IP address
|
||||||
this.hostAddress = addr.getHostAddress();
|
this.hostAddress = addr.getHostAddress();
|
||||||
// host name for the IP address
|
|
||||||
this.hostName = addr.getHostName();
|
|
||||||
}
|
}
|
||||||
this.remotePort = socket.getPort();
|
this.remotePort = socket.getPort();
|
||||||
this.responseQueue = new LinkedList<RpcCall>();
|
this.responseQueue = new LinkedList<RpcCall>();
|
||||||
@ -2102,7 +2095,7 @@ public Connection(SocketChannel channel, long lastContact,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return hostName + ":" + remotePort + " / " + hostAddress + ":" + remotePort;
|
return hostAddress + ":" + remotePort;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean setShouldClose() {
|
boolean setShouldClose() {
|
||||||
@ -2516,6 +2509,7 @@ public int readAndProcess() throws IOException, InterruptedException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!RpcConstants.HEADER.equals(dataLengthBuffer)) {
|
if (!RpcConstants.HEADER.equals(dataLengthBuffer)) {
|
||||||
|
final String hostName = addr == null ? this.hostAddress : addr.getHostName();
|
||||||
LOG.warn("Incorrect RPC Header length from {}:{} / {}:{}. Expected: {}. Actual: {}",
|
LOG.warn("Incorrect RPC Header length from {}:{} / {}:{}. Expected: {}. Actual: {}",
|
||||||
hostName, remotePort, hostAddress, remotePort, RpcConstants.HEADER,
|
hostName, remotePort, hostAddress, remotePort, RpcConstants.HEADER,
|
||||||
dataLengthBuffer);
|
dataLengthBuffer);
|
||||||
@ -2523,6 +2517,7 @@ public int readAndProcess() throws IOException, InterruptedException {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (version != CURRENT_VERSION) {
|
if (version != CURRENT_VERSION) {
|
||||||
|
final String hostName = addr == null ? this.hostAddress : addr.getHostName();
|
||||||
//Warning is ok since this is not supposed to happen.
|
//Warning is ok since this is not supposed to happen.
|
||||||
LOG.warn("Version mismatch from {}:{} / {}:{}. "
|
LOG.warn("Version mismatch from {}:{} / {}:{}. "
|
||||||
+ "Expected version: {}. Actual version: {} ", hostName,
|
+ "Expected version: {}. Actual version: {} ", hostName,
|
||||||
|
@ -1177,7 +1177,7 @@ private static void callAndVerify(Server server, InetSocketAddress addr,
|
|||||||
Connection connection = server.getConnections()[0];
|
Connection connection = server.getConnections()[0];
|
||||||
LOG.info("Connection is from: {}", connection);
|
LOG.info("Connection is from: {}", connection);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Connection string representation should include both IP address and Host name", 2,
|
"Connection string representation should include only IP address for healthy connection", 1,
|
||||||
connection.toString().split(" / ").length);
|
connection.toString().split(" / ").length);
|
||||||
int serviceClass2 = connection.getServiceClass();
|
int serviceClass2 = connection.getServiceClass();
|
||||||
assertFalse(noChanged ^ serviceClass == serviceClass2);
|
assertFalse(noChanged ^ serviceClass == serviceClass2);
|
||||||
|
@ -1941,8 +1941,8 @@ public RpcStatusProto getRpcStatusProto() {
|
|||||||
String connectionInfo = conns[0].toString();
|
String connectionInfo = conns[0].toString();
|
||||||
LOG.info("Connection is from: {}", connectionInfo);
|
LOG.info("Connection is from: {}", connectionInfo);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Connection string representation should include both IP address and Host name", 2,
|
"Connection string representation should include only IP address for healthy "
|
||||||
connectionInfo.split(" / ").length);
|
+ "connection", 1, connectionInfo.split(" / ").length);
|
||||||
// verify whether the connection should have been reused.
|
// verify whether the connection should have been reused.
|
||||||
if (isDisconnected) {
|
if (isDisconnected) {
|
||||||
assertNotSame(reqName, lastConn, conns[0]);
|
assertNotSame(reqName, lastConn, conns[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user