summaryrefslogtreecommitdiffstats
path: root/orchestrator
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@verizonmedia.com>2020-05-15 00:09:08 +0200
committerHåkon Hallingstad <hakon@verizonmedia.com>2020-05-15 00:09:08 +0200
commitad3633906838b4a3a7e49c27814471f976019520 (patch)
tree7ea7c5a98dcaae76d4bc4ed16653ab3aacf6e38e /orchestrator
parent1debd782378104ae8d23f6983f5c19aef89a21c3 (diff)
Ignore missing children from optimistic read of suspended hosts
Also: Remove test for existence of path, which would normally turn up in the negative, and instead catch NoNodeException on the next if path does not exist, at the expense of exception thrown/caught. This should be cheaper than actually hitting ZK.
Diffstat (limited to 'orchestrator')
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfosServiceImpl.java39
1 files changed, 26 insertions, 13 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfosServiceImpl.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfosServiceImpl.java
index cbb6902066e..d5cf0b39fda 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfosServiceImpl.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfosServiceImpl.java
@@ -4,7 +4,6 @@ package com.yahoo.vespa.orchestrator.status;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.jdisc.Timer;
-import java.util.logging.Level;
import com.yahoo.path.Path;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference;
import com.yahoo.vespa.applicationmodel.HostName;
@@ -14,12 +13,12 @@ import com.yahoo.vespa.orchestrator.status.json.WireHostInfo;
import org.apache.zookeeper.KeeperException.NoNodeException;
import java.time.Instant;
+import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.stream.Collectors;
/**
* Handles all ZooKeeper data structures related to each active application, including HostInfo.
@@ -42,18 +41,32 @@ public class HostInfosServiceImpl implements HostInfosService {
public HostInfos getHostInfos(ApplicationInstanceReference reference) {
ApplicationId application = OrchestratorUtil.toApplicationId(reference);
String hostsRootPath = hostsPath(application);
- if (uncheck(() -> curator.framework().checkExists().forPath(hostsRootPath)) == null) {
+
+ List<String> hostnames;
+ try {
+ hostnames = curator.framework().getChildren().forPath(hostsRootPath);
+ } catch (NoNodeException e) {
return new HostInfos();
- } else {
- List<String> hostnames = uncheck(() -> curator.framework().getChildren().forPath(hostsRootPath));
- Map<HostName, HostInfo> hostInfos = hostnames.stream().collect(Collectors.toMap(
- hostname -> new HostName(hostname),
- hostname -> {
- byte[] bytes = uncheck(() -> curator.framework().getData().forPath(hostsRootPath + "/" + hostname));
- return WireHostInfo.deserialize(bytes);
- }));
- return new HostInfos(hostInfos);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
+
+ var hostInfos = new HashMap<HostName, HostInfo>();
+ for (var hostname : hostnames) {
+ byte[] bytes;
+ try {
+ bytes = curator.framework().getData().forPath(hostsRootPath + "/" + hostname);
+ } catch (NoNodeException e) {
+ // OK, node has been removed since getChildren()
+ continue;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ hostInfos.put(new HostName(hostname), WireHostInfo.deserialize(bytes));
+ }
+
+ return new HostInfos(hostInfos);
}
@Override