Skip to content

Commit

Permalink
Small refactoring. Implementor decides how to handle QueryableGraph.p…
Browse files Browse the repository at this point in the history
…refetchDeps.

PiperOrigin-RevId: 224601444
  • Loading branch information
aoeui authored and Copybara-Service committed Dec 8, 2018
1 parent e1253a3 commit 5de60f1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.util.GroupedList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -66,17 +67,17 @@ public interface QueryableGraph {
/**
* Optimistically prefetches dependencies.
*
* @param excludedKeys keys that could overlap with {@code depKeys}. {@code prefetchDeps} is
* usually called together with an actual fetch, and the keys actually fetched should be
* excluded from the prefetch.
* @see PrefetchDepsRequest
*/
default void prefetchDeps(
@Nullable SkyKey requestor, Iterable<? extends SkyKey> depKeys, Set<SkyKey> excludedKeys)
throws InterruptedException {
default void prefetchDeps(PrefetchDepsRequest request) throws InterruptedException {
if (request.oldDeps.isEmpty()) {
return;
}
request.excludedKeys = request.depKeys.toSet();
getBatchAsync(
requestor,
request.requestor,
Reason.PREFETCH,
Iterables.filter(depKeys, Predicates.not(Predicates.in(excludedKeys))));
Iterables.filter(request.oldDeps, Predicates.not(Predicates.in(request.excludedKeys))));
}

/**
Expand Down Expand Up @@ -157,4 +158,35 @@ enum Reason {
/** Some other reason than one of the above. */
OTHER,
}

/** Parameters for {@link QueryableGraph#prefetchDeps}. */
static class PrefetchDepsRequest {
public final SkyKey requestor;

/**
* Old dependencies to prefetch.
*
* <p>The implementation might ignore this if it has another way to determine the dependencies.
*/
public final Set<SkyKey> oldDeps;

/**
* Direct deps that will be subsequently fetched and therefore should be excluded from
* prefetching.
*/
public final GroupedList<SkyKey> depKeys;

/**
* Output parameter: {@code depKeys} as a set.
*
* <p>The implementation might set this, in which case, the caller could reuse it.
*/
@Nullable public Set<SkyKey> excludedKeys = null;

public PrefetchDepsRequest(SkyKey requestor, Set<SkyKey> oldDeps, GroupedList<SkyKey> depKeys) {
this.requestor = requestor;
this.oldDeps = oldDeps;
this.depKeys = depKeys;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,18 @@ private Map<SkyKey, SkyValue> batchPrefetch(
boolean assertDone,
SkyKey keyForDebugging)
throws InterruptedException, UndonePreviouslyRequestedDep {
Set<SkyKey> depKeysAsSet = null;
QueryableGraph.PrefetchDepsRequest request = null;
if (PREFETCH_OLD_DEPS) {
if (!oldDeps.isEmpty()) {
// Create a set here so that filtering the old deps below is fast. Once we create this set,
// we may as well use it for the call to evaluatorContext#getBatchValues since we've
// precomputed the size.
depKeysAsSet = depKeys.toSet();
evaluatorContext.getGraph().prefetchDeps(requestor, oldDeps, depKeysAsSet);
}
request = new QueryableGraph.PrefetchDepsRequest(requestor, oldDeps, depKeys);
evaluatorContext.getGraph().prefetchDeps(request);
}
Map<SkyKey, ? extends NodeEntry> batchMap =
evaluatorContext.getBatchValues(
requestor,
Reason.PREFETCH,
depKeysAsSet == null ? depKeys.getAllElementsAsIterable() : depKeysAsSet);
(request != null && request.excludedKeys != null)
? request.excludedKeys
: depKeys.getAllElementsAsIterable());
if (batchMap.size() != depKeys.numElements()) {
NodeEntry inFlightEntry = null;
try {
Expand Down

0 comments on commit 5de60f1

Please sign in to comment.