ptupitsyn commented on code in PR #7031:
URL: https://github.com/apache/ignite-3/pull/7031#discussion_r2567758169


##########
modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java:
##########
@@ -414,20 +423,46 @@ public CompletableFuture<ClientChannel> 
getChannelAsync(@Nullable String preferr
      * @return host:port_range address lines parsed as {@link 
InetSocketAddress} as a key. Value is the amount of appearences of an address
      *         in {@code addrs} parameter.
      */
-    private static Map<InetSocketAddress, Integer> parsedAddresses(String[] 
addrs) {
+    private static Map<InetSocketAddress, Integer> 
parsedAddresses(InetAddressResolver addressResolver, String[] addrs) {
         if (addrs == null || addrs.length == 0) {
             throw new IgniteException(CONFIGURATION_ERR, "Empty addresses");
         }
 
-        Collection<HostAndPort> ranges = new ArrayList<>(addrs.length);
+        Collection<HostAndPort> parsedAddrs = new ArrayList<>(addrs.length);
 
         for (String a : addrs) {
-            ranges.add(HostAndPort.parse(a, 
IgniteClientConfiguration.DFLT_PORT, "Failed to parse Ignite server address"));
+            parsedAddrs.add(HostAndPort.parse(a, 
IgniteClientConfiguration.DFLT_PORT, "Failed to parse Ignite server address"));
         }
 
-        return ranges.stream()
-                .map(p -> InetSocketAddress.createUnresolved(p.host(), 
p.port()))
-                .collect(Collectors.toMap(a -> a, a -> 1, Integer::sum));
+        var map = new HashMap<InetSocketAddress, Integer>(parsedAddrs.size());
+
+        for (HostAndPort addr : parsedAddrs) {
+            try {
+                // Special handling for "localhost" to avoid unnecessary DNS 
resolution.
+                if ("localhost".equalsIgnoreCase(addr.host())) {
+                    map.merge(InetSocketAddress.createUnresolved(addr.host(), 
addr.port()), 1, Integer::sum);
+
+                    continue;

Review Comment:
   Not sure about this, `localhost` can be customized in the hosts file for 
various reasons. And the OS should deal with that.



##########
modules/client/src/main/java/org/apache/ignite/internal/client/ReliableChannel.java:
##########
@@ -414,20 +423,46 @@ public CompletableFuture<ClientChannel> 
getChannelAsync(@Nullable String preferr
      * @return host:port_range address lines parsed as {@link 
InetSocketAddress} as a key. Value is the amount of appearences of an address
      *         in {@code addrs} parameter.
      */
-    private static Map<InetSocketAddress, Integer> parsedAddresses(String[] 
addrs) {
+    private static Map<InetSocketAddress, Integer> 
parsedAddresses(InetAddressResolver addressResolver, String[] addrs) {
         if (addrs == null || addrs.length == 0) {
             throw new IgniteException(CONFIGURATION_ERR, "Empty addresses");
         }
 
-        Collection<HostAndPort> ranges = new ArrayList<>(addrs.length);
+        Collection<HostAndPort> parsedAddrs = new ArrayList<>(addrs.length);
 
         for (String a : addrs) {
-            ranges.add(HostAndPort.parse(a, 
IgniteClientConfiguration.DFLT_PORT, "Failed to parse Ignite server address"));
+            parsedAddrs.add(HostAndPort.parse(a, 
IgniteClientConfiguration.DFLT_PORT, "Failed to parse Ignite server address"));
         }
 
-        return ranges.stream()
-                .map(p -> InetSocketAddress.createUnresolved(p.host(), 
p.port()))
-                .collect(Collectors.toMap(a -> a, a -> 1, Integer::sum));
+        var map = new HashMap<InetSocketAddress, Integer>(parsedAddrs.size());
+
+        for (HostAndPort addr : parsedAddrs) {
+            try {
+                // Special handling for "localhost" to avoid unnecessary DNS 
resolution.
+                if ("localhost".equalsIgnoreCase(addr.host())) {
+                    map.merge(InetSocketAddress.createUnresolved(addr.host(), 
addr.port()), 1, Integer::sum);
+
+                    continue;
+                }
+
+                for (InetAddress inetAddr : 
addressResolver.getAllByName(addr.host())) {
+                    // Preserve unresolved address if the resolved address 
equals to the original host string.

Review Comment:
   Please elaborate, why do we need this special case?



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