[grid] Ensure a Node is purged as per the heartbeat period
@@ -190,15 +190,16 @@ public void purgeDeadNodes() {
Set<NodeStatus> toRemove = new HashSet<>();
for (NodeStatus node : nodes) {
+ Instant now = Instant.now();
Instant lastTouched = nodePurgeTimes.getOrDefault(node.getNodeId(), Instant.now());
Instant lostTime = lastTouched.plus(node.getHeartbeatPeriod().multipliedBy(PURGE_TIMEOUT_MULTIPLIER / 2));
Instant deadTime = lastTouched.plus(node.getHeartbeatPeriod().multipliedBy(PURGE_TIMEOUT_MULTIPLIER));
- if (node.getAvailability() == UP && lastTouched.isBefore(lostTime)) {
+ if (node.getAvailability() == UP && lostTime.isBefore(now)) {
LOG.info(String.format("Switching node %s from UP to DOWN", node.getNodeId()));
replacements.put(node, rewrite(node, DOWN));
}
- if (node.getAvailability() == DOWN && lastTouched.isBefore(deadTime)) {
+ if (node.getAvailability() == DOWN && deadTime.isBefore(now)) {
LOG.info(String.format("Removing node %s that is DOWN for too long", node.getNodeId()));
toRemove.add(node);
}
