Skip to content

Commit ef119c7

Browse files
virajjasaniHexiaoqiao
authored andcommitted
HADOOP-19218 Avoid DNS lookup while creating IPC Connection object (apache#6916). Contributed by Viraj Jasani.
Signed-off-by: Rushabh Shah <shahrs87@apache.org> Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org> (cherry picked from commit 1360c75)
1 parent 5f0b151 commit ef119c7

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,11 +2035,7 @@ public class Connection {
20352035
* Address to which the socket is connected to.
20362036
*/
20372037
private final InetAddress addr;
2038-
/**
2039-
* Client Host address from where the socket connection is being established to the Server.
2040-
*/
2041-
private final String hostName;
2042-
2038+
20432039
IpcConnectionContextProto connectionContext;
20442040
String protocolName;
20452041
SaslServer saslServer;
@@ -2082,12 +2078,9 @@ public Connection(SocketChannel channel, long lastContact,
20822078
this.isOnAuxiliaryPort = isOnAuxiliaryPort;
20832079
if (addr == null) {
20842080
this.hostAddress = "*Unknown*";
2085-
this.hostName = this.hostAddress;
20862081
} else {
20872082
// host IP address
20882083
this.hostAddress = addr.getHostAddress();
2089-
// host name for the IP address
2090-
this.hostName = addr.getHostName();
20912084
}
20922085
this.remotePort = socket.getPort();
20932086
this.responseQueue = new LinkedList<RpcCall>();
@@ -2103,7 +2096,7 @@ public Connection(SocketChannel channel, long lastContact,
21032096

21042097
@Override
21052098
public String toString() {
2106-
return hostName + ":" + remotePort + " / " + hostAddress + ":" + remotePort;
2099+
return hostAddress + ":" + remotePort;
21072100
}
21082101

21092102
boolean setShouldClose() {
@@ -2517,13 +2510,15 @@ public int readAndProcess() throws IOException, InterruptedException {
25172510
}
25182511

25192512
if (!RpcConstants.HEADER.equals(dataLengthBuffer)) {
2513+
final String hostName = addr == null ? this.hostAddress : addr.getHostName();
25202514
LOG.warn("Incorrect RPC Header length from {}:{} / {}:{}. Expected: {}. Actual: {}",
25212515
hostName, remotePort, hostAddress, remotePort, RpcConstants.HEADER,
25222516
dataLengthBuffer);
25232517
setupBadVersionResponse(version);
25242518
return -1;
25252519
}
25262520
if (version != CURRENT_VERSION) {
2521+
final String hostName = addr == null ? this.hostAddress : addr.getHostName();
25272522
//Warning is ok since this is not supposed to happen.
25282523
LOG.warn("Version mismatch from {}:{} / {}:{}. "
25292524
+ "Expected version: {}. Actual version: {} ", hostName,

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ private static void callAndVerify(Server server, InetSocketAddress addr,
11771177
Connection connection = server.getConnections()[0];
11781178
LOG.info("Connection is from: {}", connection);
11791179
assertEquals(
1180-
"Connection string representation should include both IP address and Host name", 2,
1180+
"Connection string representation should include only IP address for healthy connection", 1,
11811181
connection.toString().split(" / ").length);
11821182
int serviceClass2 = connection.getServiceClass();
11831183
assertFalse(noChanged ^ serviceClass == serviceClass2);

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,8 +1941,8 @@ public RpcStatusProto getRpcStatusProto() {
19411941
String connectionInfo = conns[0].toString();
19421942
LOG.info("Connection is from: {}", connectionInfo);
19431943
assertEquals(
1944-
"Connection string representation should include both IP address and Host name", 2,
1945-
connectionInfo.split(" / ").length);
1944+
"Connection string representation should include only IP address for healthy "
1945+
+ "connection", 1, connectionInfo.split(" / ").length);
19461946
// verify whether the connection should have been reused.
19471947
if (isDisconnected) {
19481948
assertNotSame(reqName, lastConn, conns[0]);

0 commit comments

Comments
 (0)