浏览代码

HDFS-16588. Backport HDFS-16584 to branch-3.3. (#4342). Contributed by JiangHua Zhu.

Signed-off-by: litao <tomleescut@gmail.com>
Signed-off-by: He Xiaoqiao <hexiaoqiao@apache.org>
jianghuazhu 3 年之前
父节点
当前提交
fe6b050857

+ 6 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/NameNodeConnector.java

@@ -21,6 +21,7 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -255,6 +256,7 @@ public class NameNodeConnector implements Closeable {
     }
     boolean isRequestStandby = false;
     NamenodeProtocol nnproxy = null;
+    InetSocketAddress standbyAddress = null;
     try {
       if (requestToStandby && nsId != null
           && HAUtil.isHAEnabled(config, nsId)) {
@@ -264,8 +266,9 @@ public class NameNodeConnector implements Closeable {
           try {
             if (proxy.getHAServiceState().equals(
                 HAServiceProtocol.HAServiceState.STANDBY)) {
+              standbyAddress = RPC.getServerAddress(proxy);
               NamenodeProtocol sbn = NameNodeProxies.createNonHAProxy(
-                  config, RPC.getServerAddress(proxy), NamenodeProtocol.class,
+                  config, standbyAddress, NamenodeProtocol.class,
                   UserGroupInformation.getCurrentUser(), false).getProxy();
               nnproxy = sbn;
               isRequestStandby = true;
@@ -287,7 +290,8 @@ public class NameNodeConnector implements Closeable {
       return nnproxy.getBlocks(datanode, size, minBlockSize);
     } finally {
       if (isRequestStandby) {
-        LOG.info("Request #getBlocks to Standby NameNode success.");
+        LOG.info("Request #getBlocks to Standby NameNode success. " +
+            "remoteAddress: {}", standbyAddress.getHostString());
       }
     }
   }

+ 4 - 1
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerWithHANameNodes.java

@@ -199,13 +199,16 @@ public class TestBalancerWithHANameNodes {
     try {
       cluster.waitActive();
       cluster.transitionToActive(0);
+      String standbyNameNode = cluster.getNameNode(1).
+          getNameNodeAddress().getHostString();
       Thread.sleep(500);
       client = NameNodeProxies.createProxy(conf, FileSystem.getDefaultUri(conf),
           ClientProtocol.class).getProxy();
       doTest(conf);
       // Check getBlocks request to Standby NameNode.
       assertTrue(log.getOutput().contains(
-          "Request #getBlocks to Standby NameNode success."));
+          "Request #getBlocks to Standby NameNode success. remoteAddress: " +
+            standbyNameNode));
     } finally {
       cluster.shutdown();
     }