nva commented on code in PR #7031:
URL: https://github.com/apache/ignite-3/pull/7031#discussion_r2580796776
##########
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:
Since InetSocketAddress will now have a non-null value for the `addr` field,
InetSocketAddressHolder#hashCode will return a different value.
InetSocketAddress#createUnresolved, which was used earlier, will create an
InetSocketAddress with the 'addr` field equal to null.
I redesigned the resolution logic, keeping only the part related to the
loopback. This should cover all cases in our tests
--
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]