[ https://issues.apache.org/jira/browse/GEODE-8623?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17233725#comment-17233725 ]
ASF GitHub Bot commented on GEODE-8623: --------------------------------------- jinmeiliao commented on a change in pull request #5743: URL: https://github.com/apache/geode/pull/5743#discussion_r525312958 ########## File path: geode-common/src/main/java/org/apache/geode/internal/Retry.java ########## @@ -47,45 +47,44 @@ public void sleep(long sleepTime, TimeUnit sleepTimeUnit) throws InterruptedExce } } - private static final SteadyClock steadyClock = new SteadyClock(); + private static final SteadyTimer steadyClock = new SteadyTimer(); /** * Try the supplier function until the predicate is true or timeout occurs. * * @param timeout to retry for + * @param timeoutUnit the unit for timeout * @param interval time between each try - * @param timeUnit to retry for + * @param intervalUnit the unit for interval * @param supplier to execute until predicate is true or times out * @param predicate to test for retry * @param <T> type of return value * @return value from supplier after it passes predicate or times out. */ - public static <T> T tryFor(long timeout, - long interval, - TimeUnit timeUnit, + public static <T> T tryFor(long timeout, TimeUnit timeoutUnit, + long interval, TimeUnit intervalUnit, Supplier<T> supplier, Predicate<T> predicate) throws TimeoutException, InterruptedException { - return tryFor(timeout, interval, timeUnit, supplier, predicate, steadyClock); + return tryFor(timeout, timeoutUnit, interval, intervalUnit, supplier, predicate, steadyClock); } @VisibleForTesting - static <T> T tryFor(long timeout, - long interval, - TimeUnit timeUnit, + static <T> T tryFor(long timeout, TimeUnit timeoutUnit, + long interval, TimeUnit intervalUnit, Supplier<T> supplier, Predicate<T> predicate, - Clock clock) throws TimeoutException, InterruptedException { - long until = clock.nanoTime() + NANOSECONDS.convert(timeout, timeUnit); + Timer timer) throws TimeoutException, InterruptedException { + long until = timer.nanoTime() + NANOSECONDS.convert(timeout, timeoutUnit); T value; do { value = supplier.get(); if (predicate.test(value)) { return value; } else { - clock.sleep(interval, timeUnit); + timer.sleep(interval, intervalUnit); Review comment: @Bill Your example is a special case where the LAST iteration is the ONLY iteration. The extra computing only makes a difference in the LAST iteration and only when it throws a TimeoutException. I will try to make my case one more time, if after this, you guys still insist, I will rest my case. 1. Without the extra calculation, we would NEVER delay a normal return, we will only delay a TimeoutException by a little bit (maximum the rest period). Since we are going to timeout anyway, I don't really care about this little extra wait time. 2. The extra calculation only make a difference in the last iteration when it's about to reach a timeout, for all the previous loops, it's a waste of time and an extra call to the timer.getTime(). 3. `until - now` could be negative, so the calculation should really be something like `min(interval, (until - now) < 0 ? 0 : (until - now)` which completely take the beauty and readability out of the code. To me, the detriment overweights the benefit. But if you guys still think otherwise, do let me know. I will make the change. @Bill @pivotal-jbarrett ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Timing between DNS and Geode startup can result in permanent unknown host > exceptions. > ------------------------------------------------------------------------------------- > > Key: GEODE-8623 > URL: https://issues.apache.org/jira/browse/GEODE-8623 > Project: Geode > Issue Type: Bug > Affects Versions: 1.9.0, 1.9.1, 1.10.0, 1.9.2, 1.11.0, 1.12.0, 1.13.0, > 1.14.0, 1.13.1 > Reporter: Jacob Barrett > Priority: Minor > Labels: pull-request-available > > In a managed environment were local host name DNS entries and the startup of > Geode happen concurrently it is possible for Geode to fail name resolution in > the local hostname caching. If it fails to resolve the local hostname when > loading the caching utility class then any service dependent on this name > will fail without chance for recovery. > {code} > [error 2020/09/30 19:50:21.644 UTC <main> tid=0x1] Jmx manager could not be > started because java.net.UnknownHostException > org.apache.geode.management.ManagementException: java.net.UnknownHostException > at > org.apache.geode.management.internal.ManagementAgent.startAgent(ManagementAgent.java:133) > at > org.apache.geode.management.internal.SystemManagementService.startManager(SystemManagementService.java:432) > at > org.apache.geode.management.internal.beans.ManagementAdapter.handleCacheCreation(ManagementAdapter.java:181) > at > org.apache.geode.management.internal.beans.ManagementListener.handleEvent(ManagementListener.java:127) > at > org.apache.geode.distributed.internal.InternalDistributedSystem.notifyResourceEventListeners(InternalDistributedSystem.java:2063) > at > org.apache.geode.distributed.internal.InternalDistributedSystem.handleResourceEvent(InternalDistributedSystem.java:606) > at > org.apache.geode.internal.cache.GemFireCacheImpl.initialize(GemFireCacheImpl.java:1239) > at > org.apache.geode.internal.cache.InternalCacheBuilder.create(InternalCacheBuilder.java:219) > at > org.apache.geode.internal.cache.InternalCacheBuilder.create(InternalCacheBuilder.java:171) > at org.apache.geode.cache.CacheFactory.create(CacheFactory.java:142) > at > org.apache.geode.distributed.internal.DefaultServerLauncherCacheProvider.createCache(DefaultServerLauncherCacheProvider.java:52) > at > org.apache.geode.distributed.ServerLauncher.createCache(ServerLauncher.java:887) > at > org.apache.geode.distributed.ServerLauncher.start(ServerLauncher.java:803) > at > org.apache.geode.distributed.ServerLauncher.run(ServerLauncher.java:732) > at > org.apache.geode.distributed.ServerLauncher.main(ServerLauncher.java:251) > Caused by: java.net.UnknownHostException > at > org.apache.geode.internal.net.SocketCreator.getLocalHost(SocketCreator.java:285) > at > org.apache.geode.management.internal.ManagementAgent.configureAndStart(ManagementAgent.java:310) > at > org.apache.geode.management.internal.ManagementAgent.startAgent(ManagementAgent.java:131) > ... 14 more > [error 2020/09/30 19:50:21.724 UTC <main> tid=0x1] > org.apache.geode.management.ManagementException: java.net.UnknownHostException > Exception in thread "main" org.apache.geode.management.ManagementException: > java.net.UnknownHostException > at > org.apache.geode.management.internal.ManagementAgent.startAgent(ManagementAgent.java:133) > at > org.apache.geode.management.internal.SystemManagementService.startManager(SystemManagementService.java:432) > at > org.apache.geode.management.internal.beans.ManagementAdapter.handleCacheCreation(ManagementAdapter.java:181) > at > org.apache.geode.management.internal.beans.ManagementListener.handleEvent(ManagementListener.java:127) > at > org.apache.geode.distributed.internal.InternalDistributedSystem.notifyResourceEventListeners(InternalDistributedSystem.java:2063) > at > org.apache.geode.distributed.internal.InternalDistributedSystem.handleResourceEvent(InternalDistributedSystem.java:606) > at > org.apache.geode.internal.cache.GemFireCacheImpl.initialize(GemFireCacheImpl.java:1239) > at > org.apache.geode.internal.cache.InternalCacheBuilder.create(InternalCacheBuilder.java:219) > at > org.apache.geode.internal.cache.InternalCacheBuilder.create(InternalCacheBuilder.java:171) > at org.apache.geode.cache.CacheFactory.create(CacheFactory.java:142) > at > org.apache.geode.distributed.internal.DefaultServerLauncherCacheProvider.createCache(DefaultServerLauncherCacheProvider.java:52) > at > org.apache.geode.distributed.ServerLauncher.createCache(ServerLauncher.java:887) > at > org.apache.geode.distributed.ServerLauncher.start(ServerLauncher.java:803) > at > org.apache.geode.distributed.ServerLauncher.run(ServerLauncher.java:732) > at > org.apache.geode.distributed.ServerLauncher.main(ServerLauncher.java:251) > Caused by: java.net.UnknownHostException > at > org.apache.geode.internal.net.SocketCreator.getLocalHost(SocketCreator.java:285) > at > org.apache.geode.management.internal.ManagementAgent.configureAndStart(ManagementAgent.java:310) > at > org.apache.geode.management.internal.ManagementAgent.startAgent(ManagementAgent.java:131) > ... 14 more > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)