This is an automated email from the ASF dual-hosted git repository.

hexiaoqiao pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/branch-3.3 by this push:
     new 57760dfd3c9 HADOOP-19218 Avoid DNS lookup while creating IPC 
Connection object (#6916). Contributed by Viraj Jasani.
57760dfd3c9 is described below

commit 57760dfd3c93f2ce4189c15cfeacdc22916dab5b
Author: Viraj Jasani <vjas...@apache.org>
AuthorDate: Tue Jul 16 05:08:41 2024 -0800

    HADOOP-19218 Avoid DNS lookup while creating IPC Connection object (#6916). 
Contributed by Viraj Jasani.
    
    Signed-off-by: Rushabh Shah <shahr...@apache.org>
    Signed-off-by: He Xiaoqiao <hexiaoq...@apache.org>
    (cherry picked from commit 1360c7574adc5756ee432c5829d38351523c3f8e)
---
 .../src/main/java/org/apache/hadoop/ipc/Server.java         | 13 ++++---------
 .../src/test/java/org/apache/hadoop/ipc/TestIPC.java        |  2 +-
 .../src/test/java/org/apache/hadoop/ipc/TestRPC.java        |  4 ++--
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java
index 314f0632348..f6fd7f21e00 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java
@@ -1900,11 +1900,7 @@ public abstract class Server {
      * Address to which the socket is connected to.
      */
     private final InetAddress addr;
-    /**
-     * Client Host address from where the socket connection is being 
established to the Server.
-     */
-    private final String hostName;
-    
+
     IpcConnectionContextProto connectionContext;
     String protocolName;
     SaslServer saslServer;
@@ -1947,12 +1943,9 @@ public abstract class Server {
       this.isOnAuxiliaryPort = isOnAuxiliaryPort;
       if (addr == null) {
         this.hostAddress = "*Unknown*";
-        this.hostName = this.hostAddress;
       } else {
         // host IP address
         this.hostAddress = addr.getHostAddress();
-        // host name for the IP address
-        this.hostName = addr.getHostName();
       }
       this.remotePort = socket.getPort();
       this.responseQueue = new LinkedList<RpcCall>();
@@ -1968,7 +1961,7 @@ public abstract class Server {
 
     @Override
     public String toString() {
-      return hostName + ":" + remotePort + " / " + hostAddress + ":" + 
remotePort;
+      return hostAddress + ":" + remotePort;
     }
 
     boolean setShouldClose() {
@@ -2371,6 +2364,7 @@ public abstract class Server {
           }
 
           if (!RpcConstants.HEADER.equals(dataLengthBuffer)) {
+            final String hostName = addr == null ? this.hostAddress : 
addr.getHostName();
             LOG.warn("Incorrect RPC Header length from {}:{} / {}:{}. 
Expected: {}. Actual: {}",
                 hostName, remotePort, hostAddress, remotePort, 
RpcConstants.HEADER,
                 dataLengthBuffer);
@@ -2378,6 +2372,7 @@ public abstract class Server {
             return -1;
           }
           if (version != CURRENT_VERSION) {
+            final String hostName = addr == null ? this.hostAddress : 
addr.getHostName();
             //Warning is ok since this is not supposed to happen.
             LOG.warn("Version mismatch from {}:{} / {}:{}. "
                     + "Expected version: {}. Actual version: {} ", hostName,
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java
index bfbc2adbeb6..3948e0ba544 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java
@@ -1179,7 +1179,7 @@ public class TestIPC {
     Connection connection = server.getConnections()[0];
     LOG.info("Connection is from: {}", connection);
     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);
     int serviceClass2 = connection.getServiceClass();
     assertFalse(noChanged ^ serviceClass == serviceClass2);
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java
index 2d2e5831b36..335bfe28443 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java
@@ -1910,8 +1910,8 @@ public class TestRPC extends TestRpcBase {
           String connectionInfo = conns[0].toString();
           LOG.info("Connection is from: {}", connectionInfo);
           assertEquals(
-              "Connection string representation should include both IP address 
and Host name", 2,
-              connectionInfo.split(" / ").length);
+              "Connection string representation should include only IP address 
for healthy "
+                  + "connection", 1, connectionInfo.split(" / ").length);
           // verify whether the connection should have been reused.
           if (isDisconnected) {
             assertNotSame(reqName, lastConn, conns[0]);


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to