Skip to content

Commit 57760df

Browse files
virajjasaniHexiaoqiao
authored andcommitted
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> (cherry picked from commit 1360c75)
1 parent 745afa8 commit 57760df

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
@@ -1900,11 +1900,7 @@ public class Connection {
19001900
* Address to which the socket is connected to.
19011901
*/
19021902
private final InetAddress addr;
1903-
/**
1904-
* Client Host address from where the socket connection is being established to the Server.
1905-
*/
1906-
private final String hostName;
1907-
1903+
19081904
IpcConnectionContextProto connectionContext;
19091905
String protocolName;
19101906
SaslServer saslServer;
@@ -1947,12 +1943,9 @@ public Connection(SocketChannel channel, long lastContact,
19471943
this.isOnAuxiliaryPort = isOnAuxiliaryPort;
19481944
if (addr == null) {
19491945
this.hostAddress = "*Unknown*";
1950-
this.hostName = this.hostAddress;
19511946
} else {
19521947
// host IP address
19531948
this.hostAddress = addr.getHostAddress();
1954-
// host name for the IP address
1955-
this.hostName = addr.getHostName();
19561949
}
19571950
this.remotePort = socket.getPort();
19581951
this.responseQueue = new LinkedList<RpcCall>();
@@ -1968,7 +1961,7 @@ public Connection(SocketChannel channel, long lastContact,
19681961

19691962
@Override
19701963
public String toString() {
1971-
return hostName + ":" + remotePort + " / " + hostAddress + ":" + remotePort;
1964+
return hostAddress + ":" + remotePort;
19721965
}
19731966

19741967
boolean setShouldClose() {
@@ -2371,13 +2364,15 @@ public int readAndProcess() throws IOException, InterruptedException {
23712364
}
23722365

23732366
if (!RpcConstants.HEADER.equals(dataLengthBuffer)) {
2367+
final String hostName = addr == null ? this.hostAddress : addr.getHostName();
23742368
LOG.warn("Incorrect RPC Header length from {}:{} / {}:{}. Expected: {}. Actual: {}",
23752369
hostName, remotePort, hostAddress, remotePort, RpcConstants.HEADER,
23762370
dataLengthBuffer);
23772371
setupBadVersionResponse(version);
23782372
return -1;
23792373
}
23802374
if (version != CURRENT_VERSION) {
2375+
final String hostName = addr == null ? this.hostAddress : addr.getHostName();
23812376
//Warning is ok since this is not supposed to happen.
23822377
LOG.warn("Version mismatch from {}:{} / {}:{}. "
23832378
+ "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
@@ -1179,7 +1179,7 @@ private static void callAndVerify(Server server, InetSocketAddress addr,
11791179
Connection connection = server.getConnections()[0];
11801180
LOG.info("Connection is from: {}", connection);
11811181
assertEquals(
1182-
"Connection string representation should include both IP address and Host name", 2,
1182+
"Connection string representation should include only IP address for healthy connection", 1,
11831183
connection.toString().split(" / ").length);
11841184
int serviceClass2 = connection.getServiceClass();
11851185
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
@@ -1910,8 +1910,8 @@ public RpcStatusProto getRpcStatusProto() {
19101910
String connectionInfo = conns[0].toString();
19111911
LOG.info("Connection is from: {}", connectionInfo);
19121912
assertEquals(
1913-
"Connection string representation should include both IP address and Host name", 2,
1914-
connectionInfo.split(" / ").length);
1913+
"Connection string representation should include only IP address for healthy "
1914+
+ "connection", 1, connectionInfo.split(" / ").length);
19151915
// verify whether the connection should have been reused.
19161916
if (isDisconnected) {
19171917
assertNotSame(reqName, lastConn, conns[0]);

0 commit comments

Comments
 (0)