Skip to content

Commit 4fa5867

Browse files
justinhorvitzcopybara-github
authored andcommitted
Make lost input ownership tracking internal to ActionRewindStrategy.
Removes the option for owners to be pre-calculated and stored in `LostInputsExecException` and `LostInputsActionExecutionException`. There was only one place that was doing this. Since the calculation is now private to `ActionRewindStrategy`, we don't need `LostInputOwners` - the preconditions checks are unnecessary, since we know that `ActionRewindStrategy` calculates owners correctly. PiperOrigin-RevId: 878563149 Change-Id: Ie3c757d86a87a7cc87d853d030d6cef4cabbb717
1 parent 2fe639e commit 4fa5867

File tree

11 files changed

+50
-213
lines changed

11 files changed

+50
-213
lines changed

src/main/java/com/google/devtools/build/lib/actions/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ java_library(
174174
"//src/main/java/com/google/devtools/build/lib/skyframe:detailed_exceptions",
175175
"//src/main/java/com/google/devtools/build/lib/skyframe:sane_analysis_exception",
176176
"//src/main/java/com/google/devtools/build/lib/skyframe:tree_artifact_value",
177-
"//src/main/java/com/google/devtools/build/lib/skyframe/rewinding:lost_input_owners",
178177
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization:visible-for-serialization",
179178
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant",
180179
"//src/main/java/com/google/devtools/build/lib/starlarkbuildapi",
@@ -474,7 +473,6 @@ java_library(
474473
":actions",
475474
":artifacts",
476475
"//src/main/java/com/google/devtools/build/lib/skyframe:detailed_exceptions",
477-
"//src/main/java/com/google/devtools/build/lib/skyframe/rewinding:lost_input_owners",
478476
"//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code",
479477
"//src/main/java/com/google/devtools/build/lib/vfs",
480478
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",

src/main/java/com/google/devtools/build/lib/actions/ImportantOutputHandler.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
import com.google.common.collect.ImmutableSetMultimap;
1919
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
2020
import com.google.devtools.build.lib.skyframe.DetailedException;
21-
import com.google.devtools.build.lib.skyframe.rewinding.LostInputOwners;
2221
import com.google.devtools.build.lib.util.DetailedExitCode;
2322
import com.google.devtools.build.lib.vfs.Path;
2423
import com.google.devtools.build.lib.vfs.PathFragment;
2524
import java.time.Duration;
2625
import java.util.Collection;
2726
import java.util.Map;
28-
import java.util.Optional;
2927

3028
/** Context to be informed of top-level outputs and their runfiles. */
3129
public interface ImportantOutputHandler extends ActionContext {
@@ -139,21 +137,14 @@ void processWorkspaceStatusOutputs(Path stableOutput, Path volatileOutput)
139137
void processTooLargeStdoutErr(Path stdoutErr)
140138
throws ImportantOutputException, InterruptedException;
141139

142-
/**
143-
* Represents artifacts that need to be regenerated via action rewinding, optionally along with
144-
* their owners if known. If {@code owners} is present, the ownership information must be
145-
* complete.
146-
*/
147-
record LostArtifacts(
148-
ImmutableSetMultimap<String, ActionInput> byDigest, Optional<LostInputOwners> owners) {
140+
/** Represents artifacts that need to be regenerated via action rewinding. */
141+
record LostArtifacts(ImmutableSetMultimap<String, ActionInput> byDigest) {
149142

150143
/** An empty instance of {@link LostArtifacts}. */
151-
public static final LostArtifacts EMPTY =
152-
new LostArtifacts(ImmutableSetMultimap.of(), Optional.of(new LostInputOwners()));
144+
public static final LostArtifacts EMPTY = new LostArtifacts(ImmutableSetMultimap.of());
153145

154146
public LostArtifacts {
155147
checkNotNull(byDigest);
156-
checkNotNull(owners);
157148
}
158149

159150
public boolean isEmpty() {
@@ -163,7 +154,7 @@ public boolean isEmpty() {
163154
/** Throws {@link LostInputsExecException} if this instance is not empty. */
164155
public void throwIfNotEmpty() throws LostInputsExecException {
165156
if (!isEmpty()) {
166-
throw new LostInputsExecException(byDigest, owners, /* cause= */ null);
157+
throw new LostInputsExecException(byDigest);
167158
}
168159
}
169160
}

src/main/java/com/google/devtools/build/lib/actions/LostInputsActionExecutionException.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
import com.google.common.base.Preconditions;
1818
import com.google.common.collect.ImmutableSetMultimap;
19-
import com.google.devtools.build.lib.skyframe.rewinding.LostInputOwners;
2019
import com.google.devtools.build.lib.util.DetailedExitCode;
2120
import com.google.devtools.build.lib.util.io.FileOutErr;
2221
import com.google.devtools.build.lib.vfs.Path;
23-
import java.util.Optional;
2422
import javax.annotation.Nullable;
2523

2624
/**
@@ -32,14 +30,6 @@ public final class LostInputsActionExecutionException extends ActionExecutionExc
3230
/** Maps lost input digests to their {@link ActionInput}s. */
3331
private final ImmutableSetMultimap<String, ActionInput> lostInputs;
3432

35-
/**
36-
* Optional mapping of lost inputs to their owning expansion artifacts (tree artifacts, filesets,
37-
* runfiles).
38-
*
39-
* <p>See {@link LostInputsExecException} for details on whether this should be provided.
40-
*/
41-
private final Optional<LostInputOwners> owners;
42-
4333
/**
4434
* The {@link ActionLookupData} for the action whose evaluation failed. Used to distinguish
4535
* whether an action handling this exception was primary in its set of shared actions. Event
@@ -73,23 +63,17 @@ public final class LostInputsActionExecutionException extends ActionExecutionExc
7363
public LostInputsActionExecutionException(
7464
String message,
7565
ImmutableSetMultimap<String, ActionInput> lostInputs,
76-
Optional<LostInputOwners> owners,
7766
Action action,
7867
Exception cause,
7968
DetailedExitCode detailedExitCode) {
8069
super(message, cause, action, /* catastrophe= */ false, detailedExitCode);
8170
this.lostInputs = lostInputs;
82-
this.owners = owners;
8371
}
8472

8573
public ImmutableSetMultimap<String, ActionInput> getLostInputs() {
8674
return lostInputs;
8775
}
8876

89-
public Optional<LostInputOwners> getOwners() {
90-
return owners;
91-
}
92-
9377
public Path getPrimaryOutputPath() {
9478
return primaryOutputPath;
9579
}
@@ -149,6 +133,6 @@ public LostInputsExecException toExecException() {
149133
Preconditions.checkState(primaryOutputPath == null);
150134
Preconditions.checkState(fileOutErr == null);
151135
Preconditions.checkState(!fromInputDiscovery);
152-
return new LostInputsExecException(lostInputs, owners, this);
136+
return new LostInputsExecException(lostInputs, this);
153137
}
154138
}

src/main/java/com/google/devtools/build/lib/actions/LostInputsExecException.java

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
package com.google.devtools.build.lib.actions;
1616

1717
import static com.google.common.base.Preconditions.checkArgument;
18-
import static com.google.common.base.Preconditions.checkNotNull;
1918

2019
import com.google.common.annotations.VisibleForTesting;
2120
import com.google.common.collect.ImmutableSetMultimap;
2221
import com.google.devtools.build.lib.server.FailureDetails.Execution;
2322
import com.google.devtools.build.lib.server.FailureDetails.Execution.Code;
2423
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
25-
import com.google.devtools.build.lib.skyframe.rewinding.LostInputOwners;
2624
import com.google.devtools.build.lib.util.DetailedExitCode;
27-
import java.util.Optional;
2825
import javax.annotation.Nullable;
2926

3027
/**
@@ -36,50 +33,25 @@ public final class LostInputsExecException extends ExecException {
3633
/** Maps lost input digests to their {@link ActionInput}s. */
3734
private final ImmutableSetMultimap<String, ActionInput> lostInputs;
3835

39-
/**
40-
* Optional mapping of lost inputs to their owning expansion artifacts (tree artifacts, filesets,
41-
* runfiles).
42-
*
43-
* <p>If present, the mapping must be complete. Spawn runners should only provide this if they can
44-
* do so correctly and efficiently. If not provided, {@link
45-
* com.google.devtools.build.lib.skyframe.rewinding.ActionRewindStrategy} will calculate the
46-
* ownership mappings - the only benefit of providing them here is the performance benefit of
47-
* skipping that step.
48-
*/
49-
private final Optional<LostInputOwners> owners;
50-
5136
public LostInputsExecException(ImmutableSetMultimap<String, ActionInput> lostInputs) {
52-
this(lostInputs, /* owners= */ Optional.empty());
53-
}
54-
55-
public LostInputsExecException(
56-
ImmutableSetMultimap<String, ActionInput> lostInputs, Optional<LostInputOwners> owners) {
57-
this(lostInputs, owners, /* cause= */ null);
37+
this(lostInputs, /* cause= */ null);
5838
}
5939

6040
public LostInputsExecException(
61-
ImmutableSetMultimap<String, ActionInput> lostInputs,
62-
Optional<LostInputOwners> owners,
63-
@Nullable Throwable cause) {
41+
ImmutableSetMultimap<String, ActionInput> lostInputs, @Nullable Throwable cause) {
6442
super("lost inputs with digests: " + String.join(",", lostInputs.keySet()), cause);
6543
checkArgument(!lostInputs.isEmpty(), "No inputs were lost");
6644
this.lostInputs = lostInputs;
67-
this.owners = checkNotNull(owners);
6845
}
6946

7047
@VisibleForTesting
7148
public ImmutableSetMultimap<String, ActionInput> getLostInputs() {
7249
return lostInputs;
7350
}
7451

75-
@VisibleForTesting
76-
public Optional<LostInputOwners> getOwners() {
77-
return owners;
78-
}
79-
8052
ActionExecutionException fromExecException(String message, Action action, DetailedExitCode code) {
8153
return new LostInputsActionExecutionException(
82-
message, lostInputs, owners, action, /* cause= */ this, code);
54+
message, lostInputs, action, /* cause= */ this, code);
8355
}
8456

8557
@Override
@@ -97,8 +69,7 @@ public LostInputsExecException combine(LostInputsExecException other) {
9769
.putAll(other.lostInputs)
9870
.build();
9971
LostInputsExecException combined =
100-
new LostInputsExecException(
101-
combinedLostInputs, /* owners= */ Optional.empty(), /* cause= */ this);
72+
new LostInputsExecException(combinedLostInputs, /* cause= */ this);
10273
combined.addSuppressed(other);
10374
return combined;
10475
}

src/main/java/com/google/devtools/build/lib/remote/RemoteActionFileSystem.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,7 @@ public void createHardLink(PathFragment linkPath, PathFragment originalPath) thr
911911
public void checkForLostInputs(Action action) throws LostInputsActionExecutionException {
912912
var mergedException =
913913
lostInputs.stream()
914-
.map(
915-
lostArtifacts ->
916-
new LostInputsExecException(
917-
lostArtifacts.byDigest(), lostArtifacts.owners(), /* cause= */ null))
914+
.map(lostArtifacts -> new LostInputsExecException(lostArtifacts.byDigest()))
918915
.reduce(LostInputsExecException::combine);
919916
if (mergedException.isPresent()) {
920917
throw (LostInputsActionExecutionException)

src/main/java/com/google/devtools/build/lib/remote/common/BulkTransferException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Arrays;
2727
import java.util.List;
2828
import java.util.Objects;
29-
import java.util.Optional;
3029
import java.util.function.Function;
3130

3231
/**
@@ -114,7 +113,7 @@ public LostArtifacts getLostArtifacts(Function<PathFragment, ActionInput> action
114113
byDigestBuilder.put(DigestUtil.toString(missingDigest), actionInput);
115114
}
116115
var byDigest = byDigestBuilder.build();
117-
return new LostArtifacts(byDigest, Optional.empty());
116+
return new LostArtifacts(byDigest);
118117
}
119118

120119
@Override

src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.common.collect.ImmutableSet;
2323
import com.google.common.collect.Iterables;
2424
import com.google.devtools.build.lib.actions.ActionExecutionException;
25-
import com.google.devtools.build.lib.actions.ActionInput;
2625
import com.google.devtools.build.lib.actions.ActionInputMap;
2726
import com.google.devtools.build.lib.actions.Artifact;
2827
import com.google.devtools.build.lib.actions.CompletionContext;
@@ -424,20 +423,6 @@ private RewindPlanResult informImportantOutputHandler(
424423
return null;
425424
}
426425

427-
var owners =
428-
lostOutputs
429-
.owners()
430-
.orElseGet(
431-
() ->
432-
ActionRewindStrategy.calculateLostInputOwners(
433-
lostOutputs.byDigest().values(), metadataProvider));
434-
// Filter out lost outputs from the set of built artifacts so that they are not reported. If
435-
// rewinding is successful, we'll report them later on.
436-
for (ActionInput lostOutput : lostOutputs.byDigest().values()) {
437-
builtArtifacts.remove(lostOutput);
438-
builtArtifacts.removeAll(owners.getOwners(lostOutput));
439-
}
440-
441426
Iterable<Artifact> artifactsRelevantForRewinding = importantArtifacts;
442427
if (importantOutputHandler.requiresHiddenOutputMetadata()) {
443428
var hiddenTopLevelArtifacts =
@@ -453,7 +438,8 @@ private RewindPlanResult informImportantOutputHandler(
453438
key,
454439
ImmutableSet.copyOf(Artifact.keys(artifactsRelevantForRewinding)),
455440
lostOutputs.byDigest(),
456-
owners,
441+
metadataProvider,
442+
builtArtifacts,
457443
env);
458444
} catch (ActionRewindException | ImportantOutputException e) {
459445
LabelCause cause = new LabelCause(label, e.getDetailedExitCode());

0 commit comments

Comments
 (0)