Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a serious regression in remote execution #9287

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,13 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context)
() -> {
ExecuteRequest request = requestBuilder.build();

// Upload the command and all the inputs into the remote cache, if remote caching
// is enabled and not disabled using tags, {@see Spawns#mayBeCachedRemotely}
if (spawnCacheableRemotely) {
try (SilentCloseable c = prof.profile(UPLOAD_TIME, "upload missing inputs")) {
Map<Digest, Message> additionalInputs = Maps.newHashMapWithExpectedSize(2);
additionalInputs.put(actionKey.getDigest(), action);
additionalInputs.put(commandHash, command);
remoteCache.ensureInputsPresent(merkleTree, additionalInputs, execRoot);
}
// Upload the command and all the inputs into the remote cache.
try (SilentCloseable c = prof.profile(UPLOAD_TIME, "upload missing inputs")) {
Map<Digest, Message> additionalInputs = Maps.newHashMapWithExpectedSize(2);
additionalInputs.put(actionKey.getDigest(), action);
additionalInputs.put(commandHash, command);
remoteCache.ensureInputsPresent(merkleTree, additionalInputs, execRoot);
}

ExecuteResponse reply;
try (SilentCloseable c = prof.profile(REMOTE_EXECUTION, "execute remotely")) {
reply = remoteExecutor.executeRemotely(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import com.google.devtools.build.lib.exec.SpawnRunner.SpawnExecutionContext;
import com.google.devtools.build.lib.exec.util.FakeOwner;
import com.google.devtools.build.lib.remote.common.SimpleBlobStore.ActionKey;
import com.google.devtools.build.lib.remote.merkletree.MerkleTree;
import com.google.devtools.build.lib.remote.options.RemoteOptions;
import com.google.devtools.build.lib.remote.options.RemoteOutputsMode;
import com.google.devtools.build.lib.remote.util.DigestUtil;
Expand Down Expand Up @@ -212,7 +213,7 @@ public void nonCachableSpawnsShouldNotBeCached_localFallback() throws Exception
runner.exec(spawn, policy);

verify(localRunner).exec(spawn, policy);
verify(cache, never()).upload(any(), any(), any(), any(), any(), any());
verify(cache).ensureInputsPresent(any(), any(), eq(execRoot));
verifyNoMoreInteractions(cache);
}

Expand Down
30 changes: 30 additions & 0 deletions src/test/shell/bazel/remote/remote_execution_http_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,34 @@ EOF
rm -rf $cache
}

function test_tag_no_remote_cache() {
mkdir -p a
cat > a/BUILD <<'EOF'
genrule(
name = "foo",
srcs = [],
outs = ["foo.txt"],
cmd = "echo \"foo\" > \"$@\"",
tags = ["no-remote-cache"]
)
EOF

bazel build \
--spawn_strategy=local \
--remote_cache=grpc://localhost:${worker_port} \
//a:foo >& $TEST_log || "Failed to build //a:foo"

expect_log "1 local"

bazel clean

bazel build \
--spawn_strategy=local \
--remote_cache=grpc://localhost:${worker_port} \
//a:foo || "Failed to build //a:foo"

expect_log "1 local"
expect_not_log "remote cache hit"
}

run_suite "Remote execution and remote cache tests"
50 changes: 50 additions & 0 deletions src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,56 @@ EOF
//a:foo || "Failed to build //a:foo"
}

function test_tag_no_remote_cache() {
mkdir -p a
cat > a/BUILD <<'EOF'
genrule(
name = "foo",
srcs = [],
outs = ["foo.txt"],
cmd = "echo \"foo\" > \"$@\"",
tags = ["no-remote-cache"]
)
EOF

bazel build \
--remote_executor=grpc://localhost:${worker_port} \
//a:foo >& $TEST_log || "Failed to build //a:foo"

expect_log "1 remote"

bazel clean

bazel build \
--remote_executor=grpc://localhost:${worker_port} \
//a:foo || "Failed to build //a:foo"

expect_log "1 remote"
expect_not_log "remote cache hit"
}

function test_tag_no_remote_exec() {
mkdir -p a
cat > a/BUILD <<'EOF'
genrule(
name = "foo",
srcs = [],
outs = ["foo.txt"],
cmd = "echo \"foo\" > \"$@\"",
tags = ["no-remote-exec"]
)
EOF

bazel build \
--spawn_strategy=remote,local \
--remote_executor=grpc://localhost:${worker_port} \
//a:foo >& $TEST_log || "Failed to build //a:foo"

expect_log "1 local"
expect_not_log "1 remote"
}


# TODO(alpha): Add a test that fails remote execution when remote worker
# supports sandbox.

Expand Down