aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@verizonmedia.com>2021-09-13 12:14:47 +0200
committerValerij Fredriksen <valerijf@verizonmedia.com>2021-09-13 12:14:47 +0200
commit9f9a3da8d13802afcf0eaecb633bfee0ab24ee21 (patch)
tree9039cde6587c30783e0a1147adba184188197f0c /node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java
parent02cf4f676fc1a27bb538952e04a5ac243c1fce3f (diff)
Ensure unique NodeAgent ID for reallocations
Diffstat (limited to 'node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java')
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java
index 8c8f3d88a71..36668158dd6 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java
@@ -79,7 +79,7 @@ public class NodeAdminImpl implements NodeAdmin {
@Override
public void refreshContainersToRun(Set<NodeAgentContext> nodeAgentContexts) {
Map<String, NodeAgentContext> nodeAgentContextsByHostname = nodeAgentContexts.stream()
- .collect(Collectors.toMap(nac -> nac.hostname().value(), Function.identity()));
+ .collect(Collectors.toMap(NodeAdminImpl::nodeAgentId, Function.identity()));
// Stop and remove NodeAgents that should no longer be running
diff(nodeAgentWithSchedulerByHostname.keySet(), nodeAgentContextsByHostname.keySet())
@@ -222,4 +222,14 @@ public class NodeAdminImpl implements NodeAdmin {
NodeAgent nodeAgent = nodeAgentFactory.create(contextManager, context);
return new NodeAgentWithScheduler(nodeAgent, contextManager);
}
+
+ private static String nodeAgentId(NodeAgentContext nac) {
+ // NodeAgentImpl has some internal state that should not be reused when the same hostname is re-allocated
+ // to a different application/cluster, solve this by including reservation timestamp in the key.
+ return nac.hostname().value() + "-" + nac.node().events().stream()
+ .filter(event -> "reserved".equals(event.type()))
+ .findFirst()
+ .map(event -> Long.toString(event.at().toEpochMilli()))
+ .orElse("");
+ }
}