Skip to content

Commit

Permalink
[grid] Waiting for two missed heartbeats to mark a node DOWN and actu…
Browse files Browse the repository at this point in the history
…ally resurrect nodes after receiving a heartbeat event
  • Loading branch information
barancev committed Feb 19, 2021
1 parent 8232110 commit 75f55a3
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,11 @@ public GridModel remove(NodeId id) {

public void purgeDeadNodes() {
long now = System.currentTimeMillis();
long timeout = 30000;
Lock writeLock = lock.writeLock();
writeLock.lock();
try {
Set<NodeStatus> lost = nodes(UP).stream()
.filter(status -> now - status.touched() > status.heartbeatPeriod().toMillis())
.filter(status -> now - status.touched() > status.heartbeatPeriod().toMillis() * 2)
.collect(toSet());
Set<NodeStatus> resurrected = nodes(DOWN).stream()
.filter(status -> now - status.touched() <= status.heartbeatPeriod().toMillis())
Expand All @@ -192,6 +191,7 @@ public void purgeDeadNodes() {
resurrected.stream()
.map(node -> String.format("%s (uri: %s)", node.getId(), node.getUri()))
.collect(joining(", "))));
nodes(DOWN).removeAll(resurrected);
nodes(UP).addAll(resurrected);
}
if (dead.size() > 0) {
Expand Down

0 comments on commit 75f55a3

Please sign in to comment.