stoty commented on code in PR #6456:
URL: https://github.com/apache/hbase/pull/6456#discussion_r2302844620
##########
hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java:
##########
@@ -327,7 +335,56 @@ 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();
+ // Decodes the WAL directory name back into a ServerName.
+ // This reverses the URL encoding of IPv6 addresses done during path
creation,
+ // decoding "%3A" back to colons (:) before reconstructing ServerName.
+ if (hostname.contains(COLON_ENCODED_VALUE)) {
+ try {
+ hostname = URLDecoder.decode(sn.getHostname(),
StandardCharsets.UTF_8.name());
+ return ServerName.valueOf(hostname, sn.getPort(), sn.getStartCode());
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException("Exception occurred while decoding
server name", e);
+ }
+ }
+ return sn;
+ }
+
+ /**
+ * Checks if the provided server address is formatted as an IPv6 address.
This method uses Java's
+ * InetAddress to parse the input and confirms if the address is an instance
of Inet6Address for
+ * robust validation instead of relying on string splitting.
+ * @param serverAddress The address string to validate (can be a hostname or
IP)
+ * @return true if the address is a valid IPv6 address; false otherwise.
+ */
+ public static boolean isIpv6ServerName(String serverAddress) {
Review Comment:
This now actually checks if the name resolves to an Ipv6 address, so this
can also return true for hostnames, not just addresses.
Given that netiher IPv4 addresses, nor hostnames may contain colons, do we
even need to check for Ipv6 ?
Can't we just uncoditionally replace colons ?
--
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]