Skip to content

Commit

Permalink
Merge pull request #6515 from HenrikJannsen/distribute_evenly_restart…
Browse files Browse the repository at this point in the history
…_of_seed_nodes

Distribute evenly restart time
  • Loading branch information
alejandrogarcia83 committed Jan 12, 2023
2 parents 13e6c79 + 116118a commit 975210d
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,7 @@ public void startShutDownInterval(GracefulShutDownHandler gracefulShutDownHandle
seedNodeAddresses.sort(Comparator.comparing(NodeAddress::getFullAddress));

NodeAddress myAddress = injector.getInstance(P2PService.class).getNetworkNode().getNodeAddress();
int myIndex = -1;
for (int i = 0; i < seedNodeAddresses.size(); i++) {
if (seedNodeAddresses.get(i).equals(myAddress)) {
myIndex = i;
break;
}
}
int myIndex = seedNodeAddresses.indexOf(myAddress);

if (myIndex == -1) {
log.warn("We did not find our node address in the seed nodes repository. " +
Expand Down Expand Up @@ -184,11 +178,13 @@ public void startShutDownInterval(GracefulShutDownHandler gracefulShutDownHandle
// triggered multiple times after a restart while being in the same hour. It can be that we miss our target
// hour during that delay but that is not considered problematic, the seed would just restart a bit longer than
// 24 hours.
int target = myIndex;
UserThread.runAfter(() -> {
// We check every hour if we are in the target hour.
UserThread.runPeriodically(() -> {
int currentHour = ZonedDateTime.ofInstant(Instant.now(), ZoneId.of("UTC")).getHour();

// distribute evenly between 0-23
long target = Math.round(24d / seedNodeAddresses.size() * myIndex) % 24;
if (currentHour == target) {
log.warn("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" +
"Shut down node at hour {} (UTC time is {})" +
Expand Down

0 comments on commit 975210d

Please sign in to comment.