Skip to content

Commit

Permalink
Treat runfiles middlemen as aggregating middlemen.
Browse files Browse the repository at this point in the history
The goal is to, for an action execution, make only a single skyframe
edge to every required runfiles tree rather than an edge to every
runfiles artifact directly. We accomplish this by pulling the runfiles
artifacts' metadata for a particular runfiles tree through the
appropriate runfiles middlemen artifact in one batch. This CL fixes
#3217.

This change makes runfiles middlemen more similar to aggregating
middlemen. We however continue to treat runfiles middlemen slightly
differently than true aggregating middlemen. Namely, we do not expand
runfiles middlemen into the final action inputs. The reasons for this
are:

1. It can make latent bugs like
#4033 more severe.

2. The runfiles tree builder action's output MANIFEST contains
absolute paths, which interferes with remote execution if its metadata
is added to a cache hash.

3. In the sandbox, it causes the runfiles artifacts to be mounted at
their exec path locations in addition to within the runfiles
trees. This makes the sandbox less strict. (Perhaps tolerably?)

4. It saves a modicum of (transient) memory and time to not expand.

If the first two issues are fixed, it could be a nice simplification
to completely replace runfiles middlemen with aggregating middlemen.

Change-Id: I2d2148297f897af4c4c6dc055d87f8a6fad0061e
PiperOrigin-RevId: 198307109
  • Loading branch information
benjaminp authored and Copybara-Service committed May 28, 2018
1 parent 0df597e commit c868c47
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ public SkyValue compute(SkyKey skyKey, Environment env) throws ActionExecutionFu
*/
@Nullable
private AllInputs collectInputs(Action action, Environment env) throws InterruptedException {
Iterable<Artifact> allKnownInputs = Iterables.concat(
action.getInputs(), action.getRunfilesSupplier().getArtifacts());
Iterable<Artifact> allKnownInputs = action.getInputs();
if (action.inputsDiscovered()) {
return new AllInputs(allKnownInputs);
}
Expand Down Expand Up @@ -677,11 +676,15 @@ private Pair<MutableInputArtifactData, Map<Artifact, Collection<Artifact>>> chec
// We have to cache the "digest" of the aggregating value itself,
// because the action cache checker may want it.
inputArtifactData.put(input, aggregatingValue.getSelfData());
ImmutableList.Builder<Artifact> expansionBuilder = ImmutableList.builder();
for (Pair<Artifact, FileArtifactValue> pair : aggregatingValue.getInputs()) {
expansionBuilder.add(pair.first);
// Runfiles artifacts are not expanded into the action's inputs but their metadata is
// available from the action file cache.
if (!(value instanceof RunfilesArtifactValue)) {
ImmutableList.Builder<Artifact> expansionBuilder = ImmutableList.builder();
for (Pair<Artifact, FileArtifactValue> pair : aggregatingValue.getInputs()) {
expansionBuilder.add(pair.first);
}
expandedArtifacts.put(input, expansionBuilder.build());
}
expandedArtifacts.put(input, expansionBuilder.build());
} else if (value instanceof TreeArtifactValue) {
TreeArtifactValue treeValue = (TreeArtifactValue) value;
expandedArtifacts.put(input, ImmutableSet.<Artifact>copyOf(treeValue.getChildren()));
Expand All @@ -706,7 +709,7 @@ private Pair<MutableInputArtifactData, Map<Artifact, Collection<Artifact>>> chec
actionFailures++;
// Prefer a catastrophic exception as the one we propagate.
if (firstActionExecutionException == null
|| !firstActionExecutionException.isCatastrophe() && e.isCatastrophe()) {
|| (!firstActionExecutionException.isCatastrophe() && e.isCatastrophe())) {
firstActionExecutionException = e;
}
rootCauses.addTransitive(e.getRootCauses());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,24 @@ private static AggregatingArtifactValue createAggregatingValue(
}
inputs.add(Pair.of(input, (FileArtifactValue) inputValue));
}
return new AggregatingArtifactValue(inputs.build(), value);
return (action.getActionType() == MiddlemanType.AGGREGATING_MIDDLEMAN)
? new AggregatingArtifactValue(inputs.build(), value)
: new RunfilesArtifactValue(inputs.build(), value);
}

/**
* Returns whether this value needs to contain the data of all its inputs. Currently only tests to
* see if the action is an aggregating middleman action. However, may include runfiles middleman
* actions and Fileset artifacts in the future.
* see if the action is an aggregating or runfiles middleman action. However, may include Fileset
* artifacts in the future.
*/
private static boolean isAggregatingValue(ActionAnalysisMetadata action) {
return action.getActionType() == MiddlemanType.AGGREGATING_MIDDLEMAN;
switch (action.getActionType()) {
case AGGREGATING_MIDDLEMAN:
case RUNFILES_MIDDLEMAN:
return true;
default:
return false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2018 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.skyframe;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.util.Pair;

/** The artifacts behind a runfiles middleman. */
class RunfilesArtifactValue extends AggregatingArtifactValue {
RunfilesArtifactValue(
ImmutableList<Pair<Artifact, FileArtifactValue>> inputs, FileArtifactValue selfData) {
super(inputs, selfData);
}
}

0 comments on commit c868c47

Please sign in to comment.