Skip to content

Commit fdf027b

Browse files
Communicate persistent worker protocol to remote execution service
This gives remote execution services the information required to correctly handle remote persistent workers that do not use the default protocol. Closes #28405. RELNOTES: The `requires-worker-protocol` execution requirement is now forwarded to remote execution services as a platform property to support intermixing JSON and Proto remote persistent worker protocols across a build.
1 parent b28d78f commit fdf027b

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,17 @@ public RemoteAction buildRemoteAction(
528528

529529
// Get the remote platform properties.
530530
Platform platform;
531+
ImmutableMap.Builder<String, String> additionalPropertiesBuilder = ImmutableMap.builder();
531532
if (toolSignature != null) {
532-
platform =
533-
PlatformUtils.getPlatformProto(
534-
spawn, remoteOptions, ImmutableMap.of("persistentWorkerKey", toolSignature.key));
535-
} else {
536-
platform = PlatformUtils.getPlatformProto(spawn, remoteOptions);
533+
additionalPropertiesBuilder.put("persistentWorkerKey", toolSignature.key);
534+
}
535+
if (spawn.getExecutionInfo().containsKey(ExecutionRequirements.REQUIRES_WORKER_PROTOCOL)) {
536+
additionalPropertiesBuilder.put(
537+
ExecutionRequirements.REQUIRES_WORKER_PROTOCOL,
538+
spawn.getExecutionInfo().get(ExecutionRequirements.REQUIRES_WORKER_PROTOCOL));
537539
}
540+
platform =
541+
PlatformUtils.getPlatformProto(spawn, remoteOptions, additionalPropertiesBuilder.build());
538542

539543
SpawnScrubber spawnScrubber = scrubber != null ? scrubber.forSpawn(spawn) : null;
540544
Command command =

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,6 +2636,7 @@ public void buildRemoteActionForRemotePersistentWorkers(
26362636
Spawn spawn =
26372637
new SpawnBuilder("@flagfile")
26382638
.withExecutionInfo(ExecutionRequirements.SUPPORTS_WORKERS, "1")
2639+
.withExecutionInfo(ExecutionRequirements.REQUIRES_WORKER_PROTOCOL, "json")
26392640
.withInputs(input, toolInput, runfilesArtifact)
26402641
.withTools(toolInput, runfilesArtifact)
26412642
.setPathMapper(
@@ -2726,10 +2727,16 @@ public void buildRemoteActionForRemotePersistentWorkers(
27262727
(byte[]) merkleTree.blobs().get(merkleTree.digest()),
27272728
ExtensionRegistry.getEmptyRegistry()))
27282729
.isEqualTo(rootDirectory);
2729-
assertThat(remoteAction1.getAction().getPlatform().getPropertiesList()).hasSize(1);
2730+
assertThat(remoteAction1.getAction().getPlatform().getPropertiesList()).hasSize(2);
27302731
assertThat(remoteAction1.getAction().getPlatform().getProperties(0).getName())
27312732
.isEqualTo("persistentWorkerKey");
27322733

2734+
// Ensure the worker protocol is communicated.
2735+
assertThat(remoteAction1.getAction().getPlatform().getProperties(1).getName())
2736+
.isEqualTo("requires-worker-protocol");
2737+
assertThat(remoteAction1.getAction().getPlatform().getProperties(1).getValue())
2738+
.isEqualTo("json");
2739+
27332740
// Check that if a non-tool input changes, the persistent worker key does not change.
27342741
fakeFileCache.createScratchInput(input, "value2");
27352742
var remoteAction2 = service.buildRemoteAction(spawn, context);
@@ -2739,7 +2746,7 @@ public void buildRemoteActionForRemotePersistentWorkers(
27392746
// Check that if a tool input changes, the persistent worker key changes.
27402747
fakeFileCache.createScratchInput(toolInput, "worker value2");
27412748
var remoteAction3 = service.buildRemoteAction(spawn, context);
2742-
assertThat(remoteAction3.getAction().getPlatform().getPropertiesList()).hasSize(1);
2749+
assertThat(remoteAction3.getAction().getPlatform().getPropertiesList()).hasSize(2);
27432750
assertThat(remoteAction3.getAction().getPlatform().getProperties(0).getName())
27442751
.isEqualTo("persistentWorkerKey");
27452752
assertThat(remoteAction3.getAction().getPlatform().getProperties(0).getValue())

0 commit comments

Comments
 (0)