Skip to content

Commit ed68933

Browse files
coeuvrecopybara-github
authored andcommitted
Remote: Invalidate actions if previous build used BwoB and remote cache is changed from enabled to disabled.
Part of #14252. PiperOrigin-RevId: 410243297
1 parent f7b8b72 commit ed68933

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,14 @@ public RemoteOutputsStrategyConverter() {
557557
/** The maximum size of an outbound message sent via a gRPC channel. */
558558
public int maxOutboundMessageSize = 1024 * 1024;
559559

560-
public boolean isRemoteEnabled() {
561-
return !Strings.isNullOrEmpty(remoteCache) || isRemoteExecutionEnabled();
560+
/** Returns {@code true} if remote cache or disk cache is enabled. */
561+
public boolean isRemoteCacheEnabled() {
562+
return !Strings.isNullOrEmpty(remoteCache)
563+
|| !(diskCache == null || diskCache.isEmpty())
564+
|| isRemoteExecutionEnabled();
562565
}
563566

567+
/** Returns {@code true} if remote execution is enabled. */
564568
public boolean isRemoteExecutionEnabled() {
565569
return !Strings.isNullOrEmpty(remoteExecutor);
566570
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory, Configur
378378

379379
private Map<String, String> lastRemoteDefaultExecProperties;
380380
private RemoteOutputsMode lastRemoteOutputsMode;
381+
private Boolean lastRemoteCacheEnabled;
381382

382383
class PathResolverFactoryImpl implements PathResolverFactory {
383384
@Override
@@ -1727,10 +1728,25 @@ private void deleteActionsIfRemoteOptionsChanged(OptionsProvider options)
17271728
lastRemoteDefaultExecProperties != null
17281729
&& !remoteDefaultExecProperties.equals(lastRemoteDefaultExecProperties);
17291730
lastRemoteDefaultExecProperties = remoteDefaultExecProperties;
1731+
1732+
boolean remoteCacheEnabled = remoteOptions != null && remoteOptions.isRemoteCacheEnabled();
1733+
// If we have remote metadata from last build, and the remote cache is not
1734+
// enabled in this build, invalidate actions since they can't download those
1735+
// remote files.
1736+
//
1737+
// TODO(chiwang): Re-evaluate this after action rewinding is implemented in
1738+
// Bazel since we can treat that case as lost inputs.
1739+
if (lastRemoteOutputsMode != RemoteOutputsMode.ALL) {
1740+
needsDeletion |=
1741+
lastRemoteCacheEnabled != null && lastRemoteCacheEnabled && !remoteCacheEnabled;
1742+
}
1743+
lastRemoteCacheEnabled = remoteCacheEnabled;
1744+
17301745
RemoteOutputsMode remoteOutputsMode =
17311746
remoteOptions != null ? remoteOptions.remoteOutputsMode : RemoteOutputsMode.ALL;
17321747
needsDeletion |= lastRemoteOutputsMode != null && lastRemoteOutputsMode != remoteOutputsMode;
17331748
this.lastRemoteOutputsMode = remoteOutputsMode;
1749+
17341750
if (needsDeletion) {
17351751
memoizingEvaluator.delete(k -> SkyFunctions.ACTION_EXECUTION.equals(k.functionName()));
17361752
}

src/test/shell/bazel/remote/remote_execution_test.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,4 +3204,50 @@ EOF
32043204
expect_not_log "WARNING: Writing to Remote Cache:"
32053205
}
32063206

3207+
function test_download_toplevel_when_turn_remote_cache_off() {
3208+
# Test that BwtB doesn't cause build failure if remote cache is disabled in a following build.
3209+
# See https://github.com/bazelbuild/bazel/issues/13882.
3210+
3211+
cat > .bazelrc <<EOF
3212+
build --verbose_failures
3213+
EOF
3214+
mkdir a
3215+
cat > a/BUILD <<'EOF'
3216+
genrule(
3217+
name = "producer",
3218+
outs = ["a.txt", "b.txt"],
3219+
cmd = "touch $(OUTS)",
3220+
)
3221+
genrule(
3222+
name = "consumer",
3223+
outs = ["out.txt"],
3224+
srcs = [":b.txt", "in.txt"],
3225+
cmd = "cat $(SRCS) > $@",
3226+
)
3227+
EOF
3228+
echo 'foo' > a/in.txt
3229+
3230+
# populate the cache
3231+
bazel build \
3232+
--remote_cache=grpc://localhost:${worker_port} \
3233+
--remote_download_toplevel \
3234+
//a:consumer >& $TEST_log || fail "Failed to populate the cache"
3235+
3236+
bazel clean >& $TEST_log || fail "Failed to clean"
3237+
3238+
# download top level outputs
3239+
bazel build \
3240+
--remote_cache=grpc://localhost:${worker_port} \
3241+
--remote_download_toplevel \
3242+
//a:consumer >& $TEST_log || fail "Failed to download outputs"
3243+
[[ -f bazel-bin/a/a.txt ]] || [[ -f bazel-bin/a/b.txt ]] \
3244+
&& fail "Expected outputs of producer are not downloaded"
3245+
3246+
# build without remote cache
3247+
echo 'bar' > a/in.txt
3248+
bazel build \
3249+
--remote_download_toplevel \
3250+
//a:consumer >& $TEST_log || fail "Failed to build without remote cache"
3251+
}
3252+
32073253
run_suite "Remote execution and remote cache tests"

0 commit comments

Comments
 (0)