You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2021/11/09 14:26:12 UTC

[hbase] branch branch-2.4 updated: HBASE-26410 Fix HBase TestCanaryTool for Java17 (#3809)

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

zhangduo pushed a commit to branch branch-2.4
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.4 by this push:
     new 563a404  HBASE-26410 Fix HBase TestCanaryTool for Java17 (#3809)
563a404 is described below

commit 563a404ac152541931b96cdcffc7c446b668c26b
Author: Yutong Xiao <yu...@gmail.com>
AuthorDate: Tue Nov 9 22:11:21 2021 +0800

    HBASE-26410 Fix HBase TestCanaryTool for Java17 (#3809)
    
    Signed-off-by: Duo Zhang <zh...@apache.org>
---
 .../java/org/apache/hadoop/hbase/util/Addressing.java     | 15 +++++++++++++++
 .../java/org/apache/hadoop/hbase/tool/CanaryTool.java     |  3 ++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java
index 46042c2..891ad35 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Addressing.java
@@ -153,6 +153,21 @@ public class Addressing {
   }
 
   /**
+   * Given an InetSocketAddress object returns a String represent of it.
+   * This is a util method for Java 17. The toString() function of InetSocketAddress
+   * will flag the unresolved address with a substring in the string, which will result
+   * in unexpected problem. We should use this util function to get the string when we
+   * not sure whether the input address is resolved or not.
+   * @param address address to convert to a "host:port" String.
+   * @return the String represent of the given address, like "foo:1234".
+   */
+  public static String inetSocketAddress2String(InetSocketAddress address) {
+    return address.isUnresolved() ?
+      address.toString().replace("/<unresolved>", "") :
+      address.toString();
+  }
+
+  /**
    * Interface for AddressSelectionCondition to check if address is acceptable
    */
   public interface AddressSelectionCondition{
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/CanaryTool.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/CanaryTool.java
index c4d44ec..1270770 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/CanaryTool.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/tool/CanaryTool.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.tool;
 
 import static org.apache.hadoop.hbase.HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT;
 import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_ZNODE_PARENT;
+import static org.apache.hadoop.hbase.util.Addressing.inetSocketAddress2String;
 import java.io.Closeable;
 import java.io.IOException;
 import java.net.BindException;
@@ -1708,7 +1709,7 @@ public class CanaryTool implements Tool, Canary {
           new ConnectStringParser(ZKConfig.getZKQuorumServersString(configuration));
       hosts = Lists.newArrayList();
       for (InetSocketAddress server : parser.getServerAddresses()) {
-        hosts.add(server.toString());
+        hosts.add(inetSocketAddress2String(server));
       }
       if (allowedFailures > (hosts.size() - 1) / 2) {
         LOG.warn(