Skip to content

Commit

Permalink
Add a flag --rewind_lost_inputs to toggle action rewinding.
Browse files Browse the repository at this point in the history
The flag value is ignored unless other rewinding prerequisites are met.

PiperOrigin-RevId: 444281575
  • Loading branch information
justinhorvitz authored and copybara-github committed Apr 25, 2022
1 parent 4e6153e commit e13958c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,16 @@ public boolean useTopLevelTargetsForSymlinks() {
help = "Whether to store output metadata in the action cache")
public boolean actionCacheStoreOutputMetadata;

@Option(
name = "rewind_lost_inputs",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.EXECUTION},
help =
"Whether to use action rewinding to recover from lost inputs. Ignored unless"
+ " prerequisites for rewinding are met (no incrementality, no action cache).")
public boolean rewindLostInputs;

@Option(
name = "discard_actions_after_execution",
defaultValue = "true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,10 @@ public WorkspaceInfoFromDiff sync(
OptionsProvider options)
throws InterruptedException, AbruptExitException {
if (evaluatorNeedsReset) {
// Rewinding is only supported with no incremental state and no action cache.
inconsistencyReceiver =
trackIncrementalState || useActionCache(options)
? GraphInconsistencyReceiver.THROWING
: new RewindableGraphInconsistencyReceiver();
rewindingPermitted(options)
? new RewindableGraphInconsistencyReceiver()
: GraphInconsistencyReceiver.THROWING;
// Recreate MemoizingEvaluator so that graph is recreated with correct edge-clearing status,
// or if the graph doesn't have edges, so that a fresh graph can be used.
resetEvaluator();
Expand All @@ -300,9 +299,15 @@ public WorkspaceInfoFromDiff sync(
return workspaceInfo;
}

private static boolean useActionCache(OptionsProvider options) {
private boolean rewindingPermitted(OptionsProvider options) {
// Rewinding is only supported with no incremental state and no action cache.
if (trackIncrementalState) {
return false;
}
BuildRequestOptions buildRequestOptions = options.getOptions(BuildRequestOptions.class);
return buildRequestOptions != null && buildRequestOptions.useActionCache;
return buildRequestOptions != null
&& !buildRequestOptions.useActionCache
&& buildRequestOptions.rewindLostInputs;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2478,20 +2478,23 @@ public NestedSet<Artifact> discoverInputs(ActionExecutionContext actionExecution

@Test
public void usesCorrectGraphInconsistencyReceiver(
@TestParameter boolean trackIncrementalState, @TestParameter boolean useActionCache)
@TestParameter boolean trackIncrementalState,
@TestParameter boolean useActionCache,
@TestParameter boolean rewindLostInputs)
throws Exception {
extraSkyFunctions.put(
SkyFunctionName.FOR_TESTING,
(key, env) -> {
if (trackIncrementalState || useActionCache) {
assertThat(env.restartPermitted()).isFalse();
} else {
if (!trackIncrementalState && !useActionCache && rewindLostInputs) {
assertThat(env.restartPermitted()).isTrue();
} else {
assertThat(env.restartPermitted()).isFalse();
}
return new SkyValue() {};
});
initializeSkyframeExecutor();
options.parse("--use_action_cache=" + useActionCache);
options.parse(
"--use_action_cache=" + useActionCache, "--rewind_lost_inputs=" + rewindLostInputs);

skyframeExecutor.setActive(false);
skyframeExecutor.decideKeepIncrementalState(
Expand Down

0 comments on commit e13958c

Please sign in to comment.