sashapolo commented on code in PR #7483:
URL: https://github.com/apache/ignite-3/pull/7483#discussion_r2735884186
##########
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);
+ } catch (UnknownHostException e) {
+ LOG.warn("Cannot resolve host \"{}\" (attempt {}/{}).",
host, tryCount, nameResolutionAttempts);
- return ArrayUtils.STRING_EMPTY_ARRAY;
- }
- }
- } while (!resolved);
+ if (tryCount >= nameResolutionAttempts) {
+ break;
+ }
- assert inetAddresses != null;
- String[] addresses = new String[inetAddresses.length];
- for (int i = 0; i < inetAddresses.length; i++) {
- InetAddress inetAddress = inetAddresses[i];
+ //noinspection BusyWait
+ Thread.sleep(tryCount * RETRY_WAIT_BASE_MILLIS);
Review Comment:
it's not 27500 ms, it's 22500, which I think is reasonable, no?
--
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]