Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distribute evenly restart time #6515

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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