srinireddy2020 commented on code in PR #6456:
URL: https://github.com/apache/hbase/pull/6456#discussion_r2296273532


##########
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)

Review Comment:
   Addressed this comment, used java standard lib functions. And verified in 
cluster with short notation, full IPv6 address and ipv6 address providing like 
with brackets [::1]



-- 
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]

Reply via email to