smengcl commented on code in PR #8853:
URL: https://github.com/apache/hadoop/pull/8853#discussion_r4366203969


##########
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java:
##########
@@ -1598,6 +1599,35 @@ void checkIfClusterIsNowMultiRack(DatanodeDescriptor 
node) {
     }
   }
 
+  /**
+   * Parse an IPv6 DataNode address given as "[addr]:port", "[addr]",
+   * "addr:port" or "addr". Without brackets, the last ':' separates the port
+   * if what follows it is a number and what precedes it is an IP literal. The
+   * address is normalized to the form DataNodes register with, see
+   * {@link InetAddress#getHostAddress()}.
+   *
+   * @param addr a DataNode address.
+   * @return the address and optional port, or null if {@code addr} has at
+   *     most one ':', that is, it is an IPv4 address or host name.
+   * @throws IllegalArgumentException if {@code addr} is not a valid IPv6
+   *     address.
+   */
+  public static HostAndPort parseIpv6Address(String addr) {
+    int idx = addr.lastIndexOf(':');
+    if (addr.indexOf(':') == idx) {
+      return null;
+    }
+    String host = addr.substring(0, idx);
+    String port = addr.substring(idx + 1);
+    HostAndPort hostPort = !addr.startsWith("[") && StringUtils.isNumeric(port)
+        && InetAddresses.isInetAddress(host)
+        ? HostAndPort.fromParts(host, Integer.parseInt(port))

Review Comment:
   Fixed in 519f0abaa23. Without brackets, a string that is a valid IPv6 
address is now never split, so `2001:db8::1:2` parses as `2001:db8:0:0:0:0:1:2` 
with no port. Added an assertion for it in `TestDatanodeManager`.
   
   The `addr:port` split still applies when the whole string is not a valid 
address. That covers what Hadoop clients send: `DFSClient` sends favored nodes 
as the expanded address plus port (`2001:db8:0:0:0:0:0:1:9866`, 9 groups), and 
the WebHDFS client sends bracketed entries. A compressed address with a port 
must be bracketed. The javadoc says so.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to