Skip to content

Commit

Permalink
Do not invalidate skyframe's in-memory action cache when changing out…
Browse files Browse the repository at this point in the history
…put mode.

Previously, we invalidate skyframe's cache if the output mode is changed from BwoB to ALL because they were two different code paths and are incompatible with each other.

Now the code paths are unifded and changing the output mode only affects the decision for whether Bazel should download outputs, no more other things.

PiperOrigin-RevId: 545641839
Change-Id: I83288f7cb505ad0e47368c702797ca365bdb4191
  • Loading branch information
coeuvre authored and pull[bot] committed Sep 5, 2023
1 parent ecb10d5 commit 5539298
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1722,11 +1722,8 @@ public void deleteActionsIfRemoteOptionsChanged(OptionsProvider options)
lastRemoteCacheEnabled != null && lastRemoteCacheEnabled && !remoteCacheEnabled;
}
lastRemoteCacheEnabled = remoteCacheEnabled;

RemoteOutputsMode remoteOutputsMode =
lastRemoteOutputsMode =
remoteOptions != null ? remoteOptions.remoteOutputsMode : RemoteOutputsMode.ALL;
needsDeletion |= lastRemoteOutputsMode != null && lastRemoteOutputsMode != remoteOutputsMode;
this.lastRemoteOutputsMode = remoteOutputsMode;

if (needsDeletion) {
memoizingEvaluator.delete(k -> SkyFunctions.ACTION_EXECUTION.equals(k.functionName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void intermediateOutputsAreInputForInternalActions_prefetchIntermediateOu
}

@Test
public void changeOutputMode_invalidateActions() throws Exception {
public void changeOutputMode_notInvalidateActions() throws Exception {
write(
"a/BUILD",
"genrule(",
Expand All @@ -210,21 +210,26 @@ public void changeOutputMode_invalidateActions() throws Exception {
" outs = ['foobar.txt'],",
" cmd = 'cat $(location :foo) > $@ && echo bar > $@',",
")");
// Download all outputs with regex so in the next build with ALL mode, the actions are not
// invalidated because of missing outputs.
addOptions("--experimental_remote_download_regex=.*");
ActionEventCollector actionEventCollector = new ActionEventCollector();
runtimeWrapper.registerSubscriber(actionEventCollector);
buildTarget("//a:foobar");
// Add the new option here because waitDownloads below will internally create a new command
// which will parse the new option.
setDownloadAll();
waitDownloads();
// 3 = workspace status action + //:foo + //:foobar
assertThat(actionEventCollector.getNumActionNodesEvaluated()).isEqualTo(3);
actionEventCollector.clear();
events.clear();

setDownloadAll();
buildTarget("//a:foobar");

// Changing output mode should invalidate SkyFrame's in-memory caching and make it re-evaluate
// the action nodes.
assertThat(actionEventCollector.getNumActionNodesEvaluated()).isEqualTo(3);
events.assertContainsInfo("2 processes: 2 remote cache hit");
// Changing output mode should not invalidate SkyFrame's in-memory caching.
assertThat(actionEventCollector.getNumActionNodesEvaluated()).isEqualTo(0);
events.assertContainsInfo("0 processes");
}

@Test
Expand Down

0 comments on commit 5539298

Please sign in to comment.