From 822c37816ac669e51bec3853b41849a19ec5e230 Mon Sep 17 00:00:00 2001 From: Nathan Harmata Date: Mon, 27 Feb 2017 21:55:56 +0000 Subject: 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 --- .../build/lib/query2/engine/VisibleFunction.java | 51 +++++++++++----------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java') 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 void eval( + public QueryTaskFuture eval( final QueryEnvironment env, - VariableContext context, + final VariableContext context, QueryExpression expression, - List args, - final Callback callback) throws QueryException, InterruptedException { - final Set toSet = QueryUtil.evalAll(env, context, args.get(0).getExpression()); - env.eval(args.get(1).getExpression(), context, new Callback() { - @Override - public void process(Iterable partialResult) throws QueryException, InterruptedException { - for (T t : partialResult) { - if (visibleToAll(env, toSet, t)) { - callback.process(ImmutableList.of(t)); + final List args, + final Callback callback) { + final QueryTaskFuture> toSetFuture = + QueryUtil.evalAll(env, context, args.get(0).getExpression()); + Function, QueryTaskFuture> computeVisibleNodesAsyncFunction = + new Function, QueryTaskFuture>() { + @Override + public QueryTaskFuture apply(final Set toSet) { + return env.eval(args.get(1).getExpression(), context, new Callback() { + @Override + public void process(Iterable partialResult) + throws QueryException, InterruptedException { + for (T t : partialResult) { + if (visibleToAll(env, toSet, t)) { + callback.process(ImmutableList.of(t)); + } + } + } + }); } - } - } - }); - } - - @Override - public void parEval( - QueryEnvironment env, - VariableContext context, - QueryExpression expression, - List args, - ThreadSafeCallback 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}. */ -- cgit v1.2.3