Skip to content

Commit 5a23ab2

Browse files
EdSchoutencopybara-github
authored andcommitted
Take the no-remote-exec tag into account when computing the action salt
Multiple times have I noticed build breakages, where people add/remove the "no-remote-exec" annotation from targets, which only came to light after existing remote cache entries expire. For example, people may try to promote a test to run remotely. "bazel test" shows the test passes, so they assume the test is safe to run remotely. Later on, the cache entry for that test expires. Or the test changes, causing its action cache key to be different. The test gets rebuilt remotely. This now fails, because the test never succeeded remotely to begin with. The cache entry belonged to the action that ran locally. Let's formalize the schema of the "salt" field. Instead of reusing the Platform message, let's declare our own message that we can use to add arbitrary properties that should be taken into account when determining the action's uniqueness. Closes #17304. PiperOrigin-RevId: 505010966 Change-Id: Ib88e769795f18b1724895ebd79835b2bc3b13e1e
1 parent 18455b3 commit 5a23ab2

File tree

6 files changed

+42
-13
lines changed

6 files changed

+42
-13
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ java_library(
112112
"//src/main/java/com/google/devtools/build/skyframe",
113113
"//src/main/java/com/google/devtools/common/options",
114114
"//src/main/protobuf:failure_details_java_proto",
115+
"//src/main/protobuf:spawn_java_proto",
115116
"//third_party:auth",
116117
"//third_party:caffeine",
117118
"//third_party:flogger",

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import com.google.devtools.build.lib.buildtool.buildevent.BuildInterruptedEvent;
7777
import com.google.devtools.build.lib.events.Event;
7878
import com.google.devtools.build.lib.events.Reporter;
79+
import com.google.devtools.build.lib.exec.Protos.CacheSalt;
7980
import com.google.devtools.build.lib.exec.SpawnInputExpander.InputWalker;
8081
import com.google.devtools.build.lib.exec.SpawnRunner.SpawnExecutionContext;
8182
import com.google.devtools.build.lib.exec.local.LocalEnvProvider;
@@ -425,18 +426,16 @@ public MerkleTree uncachedBuildMerkleTreeVisitor(
425426

426427
@Nullable
427428
private static ByteString buildSalt(Spawn spawn) {
429+
CacheSalt.Builder saltBuilder =
430+
CacheSalt.newBuilder().setMayBeExecutedRemotely(Spawns.mayBeExecutedRemotely(spawn));
431+
428432
String workspace =
429433
spawn.getExecutionInfo().get(ExecutionRequirements.DIFFERENTIATE_WORKSPACE_CACHE);
430434
if (workspace != null) {
431-
Platform platform =
432-
Platform.newBuilder()
433-
.addProperties(
434-
Platform.Property.newBuilder().setName("workspace").setValue(workspace).build())
435-
.build();
436-
return platform.toByteString();
435+
saltBuilder.setWorkspace(workspace);
437436
}
438437

439-
return null;
438+
return saltBuilder.build().toByteString();
440439
}
441440

442441
/**

src/main/protobuf/spawn.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,17 @@ message SpawnExec {
185185
// Timing, size and memory statistics.
186186
SpawnMetrics metrics = 20;
187187
}
188+
189+
// Additional information that should be taken into account when
190+
// computing the key of an action, thereby ensuring that actions remain
191+
// distinct.
192+
message CacheSalt {
193+
// Whether or not the action may be executed remotely, if remote
194+
// execution were to be enabled. This ensures that adding/removing the
195+
// "no-remote-exec" tag from a target forces a local/remote rebuild.
196+
bool may_be_executed_remotely = 1;
197+
198+
// Requires the execution service do NOT share caches across different
199+
// workspace.
200+
string workspace = 2;
201+
}

src/test/java/com/google/devtools/build/lib/remote/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ java_test(
9393
"//src/main/java/com/google/devtools/common/options",
9494
"//src/main/protobuf:failure_details_java_proto",
9595
"//src/main/protobuf:remote_execution_log_java_proto",
96+
"//src/main/protobuf:spawn_java_proto",
9697
"//src/test/java/com/google/devtools/build/lib:test_runner",
9798
"//src/test/java/com/google/devtools/build/lib/actions/util",
9899
"//src/test/java/com/google/devtools/build/lib/analysis/util",

src/test/java/com/google/devtools/build/lib/remote/RemoteExecutionServiceTest.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import com.google.devtools.build.lib.events.EventKind;
8080
import com.google.devtools.build.lib.events.Reporter;
8181
import com.google.devtools.build.lib.events.StoredEventHandler;
82+
import com.google.devtools.build.lib.exec.Protos.CacheSalt;
8283
import com.google.devtools.build.lib.exec.util.FakeOwner;
8384
import com.google.devtools.build.lib.exec.util.SpawnBuilder;
8485
import com.google.devtools.build.lib.remote.RemoteExecutionService.RemoteActionResult;
@@ -258,7 +259,7 @@ public void buildRemoteAction_withActionInputDirectoryAsOutput() throws Exceptio
258259
}
259260

260261
@Test
261-
public void buildRemoteAction_differentiateWorkspace_generateActionSalt() throws Exception {
262+
public void buildRemoteAction_generateActionSalt_differentiateWorkspaceCache() throws Exception {
262263
Spawn spawn =
263264
new SpawnBuilder("dummy")
264265
.withExecutionInfo(ExecutionRequirements.DIFFERENTIATE_WORKSPACE_CACHE, "aa")
@@ -268,10 +269,23 @@ public void buildRemoteAction_differentiateWorkspace_generateActionSalt() throws
268269

269270
RemoteAction remoteAction = service.buildRemoteAction(spawn, context);
270271

271-
Platform expected =
272-
Platform.newBuilder()
273-
.addProperties(Platform.Property.newBuilder().setName("workspace").setValue("aa"))
272+
CacheSalt expected =
273+
CacheSalt.newBuilder().setMayBeExecutedRemotely(true).setWorkspace("aa").build();
274+
assertThat(remoteAction.getAction().getSalt()).isEqualTo(expected.toByteString());
275+
}
276+
277+
@Test
278+
public void buildRemoteAction_generateActionSalt_noRemoteExec() throws Exception {
279+
Spawn spawn =
280+
new SpawnBuilder("dummy")
281+
.withExecutionInfo(ExecutionRequirements.NO_REMOTE_EXEC, "")
274282
.build();
283+
FakeSpawnExecutionContext context = newSpawnExecutionContext(spawn);
284+
RemoteExecutionService service = newRemoteExecutionService();
285+
286+
RemoteAction remoteAction = service.buildRemoteAction(spawn, context);
287+
288+
CacheSalt expected = CacheSalt.newBuilder().setMayBeExecutedRemotely(false).build();
275289
assertThat(remoteAction.getAction().getSalt()).isEqualTo(expected.toByteString());
276290
}
277291

src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public class RemoteSpawnRunnerTest {
152152

153153
// The action key of the Spawn returned by newSimpleSpawn().
154154
private final String simpleActionId =
155-
"eb45b20cc979d504f96b9efc9a08c48103c6f017afa09c0df5c70a5f92a98ea8";
155+
"31aea267dc597b047a9b6993100415b6406f82822318dc8988e4164a535b51ee";
156156

157157
@Before
158158
public final void setUp() throws Exception {
@@ -557,7 +557,7 @@ public void testHumanReadableServerLogsSavedForFailingActionWithSiblingRepositor
557557
Digest logDigest = digestUtil.computeAsUtf8("bla");
558558
Path logPath =
559559
logDir
560-
.getRelative("b9a727771337fd8ce54821f4805e2d451c4739e92fec6f8ecdb18ff9d1983b27")
560+
.getRelative("e0a5a3561464123504c1240b3587779cdfd6adee20f72aa136e388ecfd570c12")
561561
.getRelative("logname");
562562
ExecuteResponse resp =
563563
ExecuteResponse.newBuilder()

0 commit comments

Comments
 (0)