Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ public static boolean isLocalAddress(InetAddress addr) {
return local;
}

/**
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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;
Expand Down Expand Up @@ -1707,7 +1708,7 @@ protected ZookeeperMonitor(Connection connection, String[] monitorTargets, boole
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(
Expand Down