sashapolo commented on code in PR #7483:
URL: https://github.com/apache/ignite-3/pull/7483#discussion_r2735932408
##########
modules/network/src/main/java/org/apache/ignite/internal/network/StaticNodeFinder.java:
##########
@@ -84,47 +112,53 @@ public void start() {
// No-op
}
- private static String[] resolveAll(String host) {
- InetAddress[] inetAddresses = null;
+ private List<NetworkAddress> resolveAddress(NetworkAddress address) {
+ InetAddress[] inetAddresses = resolveInetAddresses(address.host());
- int tryCount = 0;
- boolean resolved = false;
+ if (inetAddresses.length == 0) {
+ return List.of();
+ }
- do {
- tryCount++;
+ var addresses = new ArrayList<NetworkAddress>(inetAddresses.length);
- try {
- inetAddresses = InetAddress.getAllByName(host);
- resolved = true;
- } catch (UnknownHostException e) {
- if (tryCount == MAX_TRIES) {
- LOG.warn("Cannot resolve {}", host);
- return ArrayUtils.STRING_EMPTY_ARRAY;
- }
+ for (InetAddress inetAddress : inetAddresses) {
+ if (inetAddress.isLoopbackAddress()) {
+ // If it's a loopback address (like 127.0.0.1), only return
this address.
+ return List.of(new
NetworkAddress(inetAddress.getHostAddress(), address.port()));
+ }
+
+ addresses.add(new NetworkAddress(inetAddress.getHostAddress(),
address.port()));
+ }
+
+ return addresses;
+ }
+
+ private InetAddress[] resolveInetAddresses(String host) {
+ try {
+ int tryCount = 1;
+ while (true) {
try {
- Thread.sleep(tryCount * RETRY_WAIT_BASE_MILLIS);
- } catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
+ return hostNameResolver.getAllByName(host);
Review Comment:
> from the code it looks like until value is expired we will get the same
value with the same UnknownHostException
Why do you think so? I've had a look at the code and I can see this:
```
try {
inetAddresses = getAddressesFromNameService(host,
reqAddr);
ex = null;
cachePolicy = InetAddressCachePolicy.get();
} catch (UnknownHostException uhe) {
inetAddresses = null;
ex = uhe;
cachePolicy = InetAddressCachePolicy.getNegative();
}
// remove or replace us with cached addresses according
to cachePolicy
if (cachePolicy == InetAddressCachePolicy.NEVER) {
cache.remove(host, this);
```
So, in case of `UnknownHostException` we will use the
`InetAddressCachePolicy.NEVER` which means that this result will not be cached.
--
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]