Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 13 additions & 4 deletions java/src/org/openqa/selenium/grid/distributor/GridModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ public void add(NodeStatus node) {
"Re-adding node with id %s and URI %s.",
node.getNodeId(), node.getExternalUri()));

events.fire(new NodeRestartedEvent(node));
// Send the previous state to allow cleaning up the old node related resources.
// Nodes are initially added in the "down" state, so the new state must be ignored.
events.fire(new NodeRestartedEvent(next));
iterator.remove();
break;
}
Expand Down Expand Up @@ -226,7 +228,8 @@ public void purgeDeadNodes() {
if (nodeHealthCount.getOrDefault(id, 0) > UNHEALTHY_THRESHOLD) {
LOG.info(
String.format(
"Removing Node %s, unhealthy threshold has been reached", node.getExternalUri()));
"Removing Node %s (uri: %s), unhealthy threshold has been reached",
node.getNodeId(), node.getExternalUri()));
toRemove.add(node);
break;
}
Expand All @@ -239,11 +242,17 @@ public void purgeDeadNodes() {
lastTouched.plus(node.getHeartbeatPeriod().multipliedBy(PURGE_TIMEOUT_MULTIPLIER));

if (node.getAvailability() == UP && lostTime.isBefore(now)) {
LOG.info(String.format("Switching Node %s from UP to DOWN", node.getExternalUri()));
LOG.info(
String.format(
"Switching Node %s (uri: %s) from UP to DOWN",
node.getNodeId(), node.getExternalUri()));
replacements.put(node, rewrite(node, DOWN));
nodePurgeTimes.put(id, Instant.now());
} else if (node.getAvailability() == DOWN && deadTime.isBefore(now)) {
LOG.info(String.format("Removing Node %s, DOWN for too long", node.getExternalUri()));
LOG.info(
String.format(
"Removing Node %s (uri: %s), DOWN for too long",
node.getNodeId(), node.getExternalUri()));
toRemove.add(node);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ public LocalDistributor(

bus.addListener(NodeStatusEvent.listener(this::register));
bus.addListener(NodeStatusEvent.listener(model::refresh));
bus.addListener(NodeRestartedEvent.listener(this::handleNodeRestarted));
bus.addListener(
NodeRestartedEvent.listener(previousNodeStatus -> remove(previousNodeStatus.getNodeId())));
bus.addListener(NodeRemovedEvent.listener(nodeStatus -> remove(nodeStatus.getNodeId())));
bus.addListener(
NodeHeartBeatEvent.listener(
Expand Down Expand Up @@ -329,25 +330,6 @@ private void register(NodeStatus status) {
}
}

private void handleNodeRestarted(NodeStatus status) {
Require.nonNull("Node", status);
Lock writeLock = lock.writeLock();
writeLock.lock();
try {
if (!nodes.containsKey(status.getNodeId())) {
return;
}
if (!getNodeFromURI(status.getExternalUri()).isDraining()) {
LOG.info(
String.format(
"Node %s has restarted. Setting availability to DOWN.", status.getNodeId()));
model.setAvailability(status.getNodeId(), DOWN);
}
} finally {
writeLock.unlock();
}
}

@Override
public LocalDistributor add(Node node) {
Require.nonNull("Node", node);
Expand Down Expand Up @@ -499,15 +481,13 @@ public void remove(NodeId nodeId) {
Lock writeLock = lock.writeLock();
writeLock.lock();
try {
Node node = nodes.get(nodeId);
Node node = nodes.remove(nodeId);
model.remove(nodeId);
allChecks.remove(nodeId);

if (node instanceof RemoteNode) {
((RemoteNode) node).close();
}

nodes.remove(nodeId);
model.remove(nodeId);
allChecks.remove(nodeId);
} finally {
writeLock.unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public JdbcBackedSessionMap(Tracer tracer, Connection jdbcConnection, EventBus b
.forEach(this::remove)));

bus.addListener(
NodeRestartedEvent.listener(nodeStatus -> this.removeByUri(nodeStatus.getExternalUri())));
NodeRestartedEvent.listener(
previousNodeStatus -> this.removeByUri(previousNodeStatus.getExternalUri())));
}

public static SessionMap create(Config config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ public LocalSessionMap(Tracer tracer, EventBus bus) {

bus.addListener(
NodeRestartedEvent.listener(
nodeStatus -> {
previousNodeStatus -> {
List<SessionId> toRemove =
knownSessions.entrySet().stream()
.filter((e) -> e.getValue().getUri().equals(nodeStatus.getExternalUri()))
.filter(
(e) -> e.getValue().getUri().equals(previousNodeStatus.getExternalUri()))
.map(Map.Entry::getKey)
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public RedisBackedSessionMap(Tracer tracer, URI serverUri, EventBus bus) {
.forEach(this::remove)));

bus.addListener(
NodeRestartedEvent.listener(nodeStatus -> this.removeByUri(nodeStatus.getExternalUri())));
NodeRestartedEvent.listener(
previousNodeStatus -> this.removeByUri(previousNodeStatus.getExternalUri())));
}

public static SessionMap create(Config config) {
Expand Down
Loading