srinireddy2020 commented on code in PR #6456:
URL: https://github.com/apache/hbase/pull/6456#discussion_r2306184251
##########
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:
“The logic has been updated and verified in the cluster with various test
cases, including hostnames and hostnames containing colons. The revised code is
functioning as expected in all scenarios.”
please check
--
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]