summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-01-10 18:37:21 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2019-01-10 18:37:21 +0100
commit5cf62f18b232d8989edfecf3097585f22e997278 (patch)
treea593a13f435a7c50c2ab248e63df6065f5544dfe /node-repository
parent9e8d4d88d9d5def49858ba1c32ed591e340b22c6 (diff)
We do not have to check for cache expiry for every node. Once for the getNodes call should do.
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorCache.java14
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java8
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java19
3 files changed, 32 insertions, 9 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorCache.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorCache.java
new file mode 100644
index 00000000000..674aa1b8f22
--- /dev/null
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorCache.java
@@ -0,0 +1,14 @@
+package com.yahoo.vespa.hosted.provision.persistence;
+
+import com.yahoo.path.Path;
+
+import java.util.List;
+import java.util.Optional;
+
+public abstract class CuratorCache {
+
+ public abstract List<String> getChildren(Path path);
+
+ public abstract Optional<byte[]> getData(Path path);
+
+} \ No newline at end of file
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java
index dd1b58dee8e..3da54a3db8c 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java
@@ -120,12 +120,12 @@ public class CuratorDatabase {
// the data to read is protected by a lock which is held now, and during any writes of the data.
/** Returns the immediate, local names of the children under this node in any order */
- List<String> getChildren(Path path) { return getCache().getChildren(path); }
+ List<String> getChildren(Path path) { return getSession().getChildren(path); }
- Optional<byte[]> getData(Path path) { return getCache().getData(path); }
+ Optional<byte[]> getData(Path path) { return getSession().getData(path); }
/** Invalidates the current cache if outdated. */
- private CuratorDatabaseCache getCache() {
+ CuratorCache getSession() {
if (changeGenerationCounter.get() != cache.get().generation)
synchronized (cacheCreationLock) {
while (changeGenerationCounter.get() != cache.get().generation)
@@ -145,7 +145,7 @@ public class CuratorDatabase {
* This is merely a recording of what Curator returned at various points in time when
* it had the counter at this generation.
*/
- private static class CuratorDatabaseCache {
+ private static class CuratorDatabaseCache extends CuratorCache {
private final long generation;
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java
index c99cccd2ab9..049f242ed2e 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabaseClient.java
@@ -258,9 +258,10 @@ public class CuratorDatabaseClient {
List<Node> nodes = new ArrayList<>();
if (states.length == 0)
states = Node.State.values();
+ CuratorCache session = curatorDatabase.getSession();
for (Node.State state : states) {
- for (String hostname : curatorDatabase.getChildren(toPath(state))) {
- Optional<Node> node = getNode(hostname, state);
+ for (String hostname : session.getChildren(toPath(state))) {
+ Optional<Node> node = getNode(session, hostname, state);
node.ifPresent(nodes::add); // node might disappear between getChildren and getNode
}
}
@@ -277,21 +278,29 @@ public class CuratorDatabaseClient {
return nodes;
}
- /**
+ /**
* Returns a particular node, or empty if this noe is not in any of the given states.
* If no states are given this returns the node if it is present in any state.
*/
- public Optional<Node> getNode(String hostname, Node.State ... states) {
+ public Optional<Node> getNode(CuratorCache session, String hostname, Node.State ... states) {
if (states.length == 0)
states = Node.State.values();
for (Node.State state : states) {
- Optional<byte[]> nodeData = curatorDatabase.getData(toPath(state, hostname));
+ Optional<byte[]> nodeData = session.getData(toPath(state, hostname));
if (nodeData.isPresent())
return nodeData.map((data) -> nodeSerializer.fromJson(state, data));
}
return Optional.empty();
}
+ /**
+ * Returns a particular node, or empty if this noe is not in any of the given states.
+ * If no states are given this returns the node if it is present in any state.
+ */
+ public Optional<Node> getNode(String hostname, Node.State ... states) {
+ return getNode(curatorDatabase.getSession(), hostname, states);
+ }
+
private Path toPath(Node.State nodeState) { return root.append(toDir(nodeState)); }
private Path toPath(Node node) {