diff options
author | jonmv <venstad@gmail.com> | 2023-08-28 15:30:37 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2023-08-28 15:30:37 +0200 |
commit | a8e2f22f3b722543c1116f1a29845ef1093dcfe8 (patch) | |
tree | 1b4f8d19d28d85bbeae9d9f60f0c8066fa4d5039 /vespajlib/src/main/java/com/yahoo/concurrent/maintenance | |
parent | 308ee70e0b33057ac9ba5852d7226c731dd52bf8 (diff) |
Spread maintainer interval boundaries based on class name hash
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/concurrent/maintenance')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java | 10 |
1 files changed, 6 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 68af9aa0a49..fdb73e405c0 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/maintenance/Maintainer.java @@ -148,14 +148,16 @@ public abstract class Maintainer implements Runnable { return name == null ? this.getClass().getSimpleName() : name; } - /** Returns the initial delay of this calculated from cluster index of given hostname */ - static Duration staggeredDelay(Duration interval, Instant now, String hostname, List<String> clusterHostnames) { + /** 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) { Objects.requireNonNull(clusterHostnames); if ( ! clusterHostnames.contains(hostname)) return interval; - long offset = clusterHostnames.indexOf(hostname) * interval.toMillis() / clusterHostnames.size(); - return Duration.ofMillis(Math.floorMod(offset - now.toEpochMilli(), interval.toMillis())); + long nodeOffset = clusterHostnames.indexOf(hostname) * interval.toMillis() / clusterHostnames.size(); + long maintainerOffset = getClass().getName().hashCode() % interval.toMillis(); + long totalOffset = nodeOffset + maintainerOffset; + return Duration.ofMillis(Math.floorMod(totalOffset - now.toEpochMilli(), interval.toMillis())); } private static Duration requireInterval(Duration interval) { |