mridulm commented on code in PR #2564:
URL: https://github.com/apache/celeborn/pull/2564#discussion_r1638985401


##########
common/src/main/scala/org/apache/celeborn/common/util/Utils.scala:
##########
@@ -415,7 +415,20 @@ object Utils extends Logging {
   }
 
   def localHostName(conf: CelebornConf): String = customHostname.getOrElse {
-    if (conf.bindPreferIP) localIpAddress.getHostAddress else 
localIpAddress.getCanonicalHostName
+    if (conf.bindPreferIP) {
+      val ipv6AddressPattern = """^\[.*]$""".r
+      localIpAddress match {
+        case ipv6: Inet6Address =>
+          if 
(ipv6AddressPattern.pattern.pattern().matches(ipv6.getHostAddress)) {
+            ipv6.getHostAddress
+          } else {
+            s"[${ipv6.getHostAddress}]"
+          }

Review Comment:
   Use scala pattern match instead ?
   Something like:
   ```suggestion
   
           // Assuming we have
           // val ipv6AddressPattern = """^(\[.*])$""".r
   
             ipv6.getHostAddress match {
               case ipv6AddressPattern(host) => host
               case ip: String => s"[ip]"
             }
   ```



##########
common/src/main/scala/org/apache/celeborn/common/util/Utils.scala:
##########
@@ -415,7 +415,20 @@ object Utils extends Logging {
   }
 
   def localHostName(conf: CelebornConf): String = customHostname.getOrElse {
-    if (conf.bindPreferIP) localIpAddress.getHostAddress else 
localIpAddress.getCanonicalHostName
+    if (conf.bindPreferIP) {
+      val ipv6AddressPattern = """^\[.*]$""".r

Review Comment:
   Move this to a object variable and avoid compiling the regex for each call.



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