diff options
author | jonmv <venstad@gmail.com> | 2023-08-29 08:18:21 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2023-08-29 08:18:21 +0200 |
commit | 63c2710a5705d361d198908be67841a4d899a83a (patch) | |
tree | c6045c68fe3d62722f2d9e9ceb6b33637bae8130 /vespajlib/src/main/java/com/yahoo/concurrent | |
parent | a8e2f22f3b722543c1116f1a29845ef1093dcfe8 (diff) |
Improve readability
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/concurrent')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java index fdb73e405c0..7fa591a88ba 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java @@ -48,9 +48,7 @@ public abstract class Maintainer implements Runnable { this.ignoreCollision = ignoreCollision; this.clock = clock; this.successFactorBaseline = successFactorBaseline; - var startedAt = clock.instant(); - Objects.requireNonNull(clusterHostnames); - Duration initialDelay = staggeredDelay(interval, startedAt, HostName.getLocalhost(), clusterHostnames) + Duration initialDelay = staggeredDelay(interval, HostName.getLocalhost(), clusterHostnames) .plus(Duration.ofSeconds(30)); // Let the system stabilize before maintenance service = new ScheduledThreadPoolExecutor(1, r -> new Thread(r, name() + "-worker")); service.scheduleAtFixedRate(this, initialDelay.toMillis(), interval.toMillis(), TimeUnit.MILLISECONDS); @@ -149,11 +147,12 @@ public abstract class Maintainer implements Runnable { } /** Returns the initial delay of this calculated from cluster index of the hostname of this node, and the maintainer name. */ - Duration staggeredDelay(Duration interval, Instant now, String hostname, List<String> clusterHostnames) { + Duration staggeredDelay(Duration interval, String hostname, List<String> clusterHostnames) { Objects.requireNonNull(clusterHostnames); if ( ! clusterHostnames.contains(hostname)) return interval; + Instant now = clock.instant(); long nodeOffset = clusterHostnames.indexOf(hostname) * interval.toMillis() / clusterHostnames.size(); long maintainerOffset = getClass().getName().hashCode() % interval.toMillis(); long totalOffset = nodeOffset + maintainerOffset; |