From 3685873df9610544826708160168f9fd66ad82b0 Mon Sep 17 00:00:00 2001 From: Janak Ramakrishnan Date: Wed, 17 Jun 2015 16:45:47 +0000 Subject: Add batch methods to WalkableGraph and convert SkyQueryEnvironment to use them. -- MOS_MIGRATED_REVID=96214911 --- .../build/skyframe/DelegatingWalkableGraph.java | 56 ++++++++++++++++++++++ .../devtools/build/skyframe/WalkableGraph.java | 23 ++++++++- 2 files changed, 77 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/google/devtools/build/skyframe') diff --git a/src/main/java/com/google/devtools/build/skyframe/DelegatingWalkableGraph.java b/src/main/java/com/google/devtools/build/skyframe/DelegatingWalkableGraph.java index 5328a487b5..fee4f9c579 100644 --- a/src/main/java/com/google/devtools/build/skyframe/DelegatingWalkableGraph.java +++ b/src/main/java/com/google/devtools/build/skyframe/DelegatingWalkableGraph.java @@ -13,7 +13,13 @@ // limitations under the License. package com.google.devtools.build.skyframe; +import com.google.common.base.Function; import com.google.common.base.Preconditions; +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; + +import java.util.Map; import javax.annotation.Nullable; @@ -33,6 +39,15 @@ public class DelegatingWalkableGraph implements WalkableGraph { return entry; } + private Map getEntries(Iterable keys) { + Map result = graph.getBatch(keys); + Preconditions.checkState(result.size() == Iterables.size(keys), "%s %s", keys, result); + for (Map.Entry entry : result.entrySet()) { + Preconditions.checkState(entry.getValue().isDone(), entry); + } + return result; + } + @Override public boolean exists(SkyKey key) { NodeEntry entry = graph.get(key); @@ -45,6 +60,21 @@ public class DelegatingWalkableGraph implements WalkableGraph { return getEntry(key).getValue(); } + private static final Function GET_SKY_VALUE_FUNCTION = + new Function() { + @Nullable + @Override + public SkyValue apply(NodeEntry entry) { + return entry.isDone() ? entry.getValue() : null; + } + }; + + @Override + public Map getValuesMaybe(Iterable keys) { + return Maps.filterValues(Maps.transformValues(graph.getBatch(keys), GET_SKY_VALUE_FUNCTION), + Predicates.notNull()); + } + @Nullable @Override public Exception getException(SkyKey key) { @@ -57,8 +87,34 @@ public class DelegatingWalkableGraph implements WalkableGraph { return getEntry(key).getDirectDeps(); } + private static final Function> GET_DIRECT_DEPS_FUNCTION = + new Function>() { + @Override + public Iterable apply(NodeEntry entry) { + return entry.getDirectDeps(); + } + }; + + @Override + public Map> getDirectDeps(Iterable keys) { + return Maps.transformValues(getEntries(keys), GET_DIRECT_DEPS_FUNCTION); + } + @Override public Iterable getReverseDeps(SkyKey key) { return getEntry(key).getReverseDeps(); } + + private static final Function> GET_REVERSE_DEPS_FUNCTION = + new Function>() { + @Override + public Iterable apply(NodeEntry entry) { + return entry.getReverseDeps(); + } + }; + + @Override + public Map> getReverseDeps(Iterable keys) { + return Maps.transformValues(getEntries(keys), GET_REVERSE_DEPS_FUNCTION); + } } diff --git a/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java b/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java index 68c39c9a2a..e020a26ba7 100644 --- a/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java +++ b/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java @@ -16,6 +16,7 @@ package com.google.devtools.build.skyframe; import com.google.devtools.build.lib.events.EventHandler; import java.util.Collection; +import java.util.Map; import javax.annotation.Nullable; @@ -39,6 +40,12 @@ public interface WalkableGraph { @Nullable SkyValue getValue(SkyKey key); + /** + * Returns a map giving the values of the given keys for done keys. Keys not present in the graph + * or whose nodes are not done will not be present in the returned map. + */ + Map getValuesMaybe(Iterable keys); + /** * Returns the exception thrown when computing the node with the given key, if any. If the node * was computed successfully, returns null. A node with this key must exist in the graph. @@ -52,11 +59,23 @@ public interface WalkableGraph { Iterable getDirectDeps(SkyKey key); /** - * Returns the reverse dependencies of the node with the given key. A node with this key must - * exist in the graph. + * Returns a map giving the direct dependencies of the nodes with the given keys. Same semantics + * as {@link #getDirectDeps(SkyKey)}. */ + Map> getDirectDeps(Iterable keys); + + /** + * Returns the reverse dependencies of the node with the given key. A node with this key must + * exist in the graph. + */ Iterable getReverseDeps(SkyKey key); + /** + * Returns a map giving the reverse dependencies of the nodes with the given keys. Same semantics + * as {@link #getReverseDeps(SkyKey)}. + */ + Map> getReverseDeps(Iterable keys); + /** Provides a WalkableGraph on demand after preparing it. */ interface WalkableGraphFactory { WalkableGraph prepareAndGet(Collection roots, int numThreads, -- cgit v1.2.3