taklwu commented on code in PR #6456:
URL: https://github.com/apache/hbase/pull/6456#discussion_r2282973734
##########
hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java:
##########
@@ -62,6 +65,12 @@ public class ServerName implements Comparable<ServerName>,
Serializable {
*/
private static final short VERSION = 0;
static final byte[] VERSION_BYTES = Bytes.toBytes(VERSION);
+ private static final String COLON_ENCODED_VALUE = "%3a";
+
+ public static final String COLON = ":";
+
+ // IPV6 address length separated by COLON(:), eg:
"0:0:0:0:0:0:0:1".split(colon).length
+ private static final int IPV6_SPLIT_COLON_LENGTH = 8;
Review Comment:
nit: just to confirm, will we never parse any ipv6 short format (that hides
the 0000) in current way of obtaining the server address?
##########
hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java:
##########
@@ -327,7 +336,49 @@ public static ServerName parseVersionedServerName(final
byte[] versionedBytes) {
* @return A ServerName instance.
*/
public static ServerName parseServerName(final String str) {
- return SERVERNAME_PATTERN.matcher(str).matches() ? valueOf(str) :
valueOf(str, NON_STARTCODE);
+ ServerName sn =
+ SERVERNAME_PATTERN.matcher(str).matches() ? valueOf(str) : valueOf(str,
NON_STARTCODE);
+ String hostname = sn.getHostname();
+ // if IPV6 address is in encoded format, need to check and validate its
address length
+ // eg: if address is like
"0%3a0%3a0%3a0%3a0%3a0%3a0%3a0%3a1,16020,1720673488765" decode to
+ // "0:0:0:0:0:0:0:1,16020,1720673488765"
+ if (isIpv6ServerName(hostname, COLON_ENCODED_VALUE)) {
+ try {
+ hostname = URLDecoder.decode(sn.getHostname(), "UTF8");
+ return ServerName.valueOf(hostname, sn.getPort(), sn.getStartCode());
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("Exception occurred while decoding
server name", e);
+ }
+ }
+ return sn;
+ }
+
+ /**
+ * Verify the ServerAddress is in IPV6 format or not
+ * @param serverAddress IP address
+ * @param addressSeparator IPV6 address separator
+ * @return true if server address is in IPV6 format
+ */
+ public static boolean isIpv6ServerName(String serverAddress, String
addressSeparator) {
+ return serverAddress.contains(addressSeparator)
+ && serverAddress.split(addressSeparator).length ==
IPV6_SPLIT_COLON_LENGTH;
Review Comment:
nit: I'm wondered if we should use the java built-in library to check the
address with `Inet6Address` (you may handle the `UnknownHostException` with
returning false as well)
```suggestion
public static boolean isIpv6ServerName(String serverAddress, String
addressSeparator) {
InetAddress address = InetAddress.getByName(serverAddress);
return address instanceof Inet6Address;
```
```
--
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]