jojochuang commented on code in PR #8853:
URL: https://github.com/apache/hadoop/pull/8853#discussion_r4364697089
##########
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:
Could we cover a portless compressed IPv6 address whose final segment is
numeric, such as `2001:db8::1:2`?
This is a valid IPv6 host with no port, but the prefix `2001:db8::1` is also
a valid IP literal, so this branch interprets it as `[2001:db8::1]:2`. For
`excludedatanodes`, that looks up the wrong address and port and leaves the
intended DataNode eligible for selection. Favored-node lookup can similarly
resolve another node or fall back.
I reproduced the parsing result using Hadoop's shaded Guava. The existing
portless test uses a fully expanded address, which doesn't exercise this
ambiguity.
Bare IPv6 hosts and legacy unbracketed IPv6 host:port strings cannot always
be distinguished by syntax alone. Could we define the intended
precedence/compatibility policy and add a regression test for this example?
Bracketed `[IPv6]:port` inputs avoid the ambiguity.
--
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]