diff options
author | Nathan Harmata <nharmata@google.com> | 2017-02-27 21:55:56 +0000 |
---|---|---|
committer | Yue Gan <yueg@google.com> | 2017-02-28 11:33:08 +0000 |
commit | 822c37816ac669e51bec3853b41849a19ec5e230 (patch) | |
tree | a12e1f438342aa9ec1846089fc255bf2abb18ad3 /src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java | |
parent | fb64609c3f1d3492f4d80807f5d91894fa147172 (diff) |
Reimplement blaze query using an async evaluation model. Use a concurrent backend for SkyQueryEnvironment's implementation in order to achieve parallelism.
Advantages:
-New design has no flaws that the old design had.
-Code is structured so that deadlocks due to thread starvation are impossible (yup!).
Disadvantages:
-The meat of this change needs to all be in a single CL because every single QueryFunction and QueryExpression needs to be rewritten in the async style.
Still TODO:
-Fully embrace the async model in all QueryFunctions (e.g. 'rdeps', 'allpaths').
-Use concurrency in BlazeQueryEnvironment to achieve parallel evaluation for (non SkyQuery) 'blaze query' and genquery.
--
PiperOrigin-RevId: 148690279
MOS_MIGRATED_REVID=148690279
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java index 532f331378..b09910c715 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java +++ b/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java @@ -14,13 +14,14 @@ package com.google.devtools.build.lib.query2.engine; +import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.ArgumentType; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; +import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryTaskFuture; import java.util.List; import java.util.Set; -import java.util.concurrent.ForkJoinPool; /** * A visible(x, y) query expression, which computes the subset of nodes in y @@ -52,34 +53,32 @@ public class VisibleFunction implements QueryFunction { } @Override - public <T> void eval( + public <T> QueryTaskFuture<Void> eval( final QueryEnvironment<T> env, - VariableContext<T> context, + final VariableContext<T> context, QueryExpression expression, - List<Argument> args, - final Callback<T> callback) throws QueryException, InterruptedException { - final Set<T> toSet = QueryUtil.evalAll(env, context, args.get(0).getExpression()); - env.eval(args.get(1).getExpression(), context, new Callback<T>() { - @Override - public void process(Iterable<T> partialResult) throws QueryException, InterruptedException { - for (T t : partialResult) { - if (visibleToAll(env, toSet, t)) { - callback.process(ImmutableList.of(t)); + final List<Argument> args, + final Callback<T> callback) { + final QueryTaskFuture<Set<T>> toSetFuture = + QueryUtil.evalAll(env, context, args.get(0).getExpression()); + Function<Set<T>, QueryTaskFuture<Void>> computeVisibleNodesAsyncFunction = + new Function<Set<T>, QueryTaskFuture<Void>>() { + @Override + public QueryTaskFuture<Void> apply(final Set<T> toSet) { + return env.eval(args.get(1).getExpression(), context, new Callback<T>() { + @Override + public void process(Iterable<T> partialResult) + throws QueryException, InterruptedException { + for (T t : partialResult) { + if (visibleToAll(env, toSet, t)) { + callback.process(ImmutableList.of(t)); + } + } + } + }); } - } - } - }); - } - - @Override - public <T> void parEval( - QueryEnvironment<T> env, - VariableContext<T> context, - QueryExpression expression, - List<Argument> args, - ThreadSafeCallback<T> callback, - ForkJoinPool forkJoinPool) throws QueryException, InterruptedException { - eval(env, context, expression, args, callback); + }; + return env.transformAsync(toSetFuture, computeVisibleNodesAsyncFunction); } /** Returns true if {@code target} is visible to all targets in {@code toSet}. */ |