Skip to content

Commit ae53991

Browse files
coeuvrecopybara-github
authored andcommitted
Remote: Add RemoteExecutionService as a layer between spawn execution and remote execution.
The initiative for this change is to let it easier to make changes to RemoteCache and other places. RemoteCache provides a set of methods to access the remote cache in a protocol independent manner and is used in the following places: - In RemoteSpawnCache (for remote cache only mode), we lookup remote cache before local execution. If no cache found, we execute the spawn locally and then upload ouputs to remote cache. - In RemoteSpawnRunner (for remote execution mode), we lookup remote cache before requesting remote execution. If no cache found, we upload inputs to remote cache, submit execution request and then download outputs from remote cache. - In RemoteRepositoryRemoteExecutor (for executing repository command remotely), we lookup remote cache and upload inputs. - In ExecutionServer (for remote worker), we download inputs from remote cache, execute the action and upload outputs to remote cache. Among these methods, only a few need spawn specific types as members, most of them are just helper functions for easily calling RemoteCacheClient. It's hard to use RemoteCache in other places since we need spawn specific types to construct it. Besides that, some state are not available at the time when we construct RemoteCache e.g. execRoot which only make sense when executing actions. It's impossible to add state as members that are only available during spawn execution to RemoteCache. We move these methods that depend spawn specific types to RemoteExecutionService so RemoteCache is decoupled from spawn execution. RemoteExecutionService is designed to provide a set of primitive operations for remote cache and execution of spawn actions. RemoteSpwanCache/RemoteSpawnRunner are the intended call sites and do the orchestration. This change only restructure the code in the call sides. Following changes will update RemoteCache. PiperOrigin-RevId: 370028737
1 parent e362fc9 commit ae53991

9 files changed

+663
-546
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ final class RemoteActionContextProvider implements ExecutorLifecycleListener {
4848
private final DigestUtil digestUtil;
4949
@Nullable private final Path logDir;
5050
private ImmutableSet<ActionInput> filesToDownload = ImmutableSet.of();
51+
private RemoteExecutionService remoteExecutionService;
5152

5253
private RemoteActionContextProvider(
5354
CommandEnvironment env,
@@ -100,6 +101,24 @@ RemotePathResolver createRemotePathResolver() {
100101
return remotePathResolver;
101102
}
102103

104+
RemoteExecutionService getRemoteExecutionService() {
105+
if (remoteExecutionService == null) {
106+
remoteExecutionService =
107+
new RemoteExecutionService(
108+
env.getExecRoot(),
109+
createRemotePathResolver(),
110+
env.getBuildRequestId(),
111+
env.getCommandId().toString(),
112+
digestUtil,
113+
checkNotNull(env.getOptions().getOptions(RemoteOptions.class)),
114+
cache,
115+
executor,
116+
filesToDownload);
117+
}
118+
119+
return remoteExecutionService;
120+
}
121+
103122
/**
104123
* Registers a remote spawn strategy if this instance was created with an executor, otherwise does
105124
* nothing.
@@ -121,15 +140,9 @@ public void registerRemoteSpawnStrategyIfApplicable(
121140
env.getOptions().getOptions(ExecutionOptions.class),
122141
verboseFailures,
123142
env.getReporter(),
124-
env.getBuildRequestId(),
125-
env.getCommandId().toString(),
126-
(RemoteExecutionCache) cache,
127-
executor,
128143
retryScheduler,
129-
digestUtil,
130144
logDir,
131-
filesToDownload,
132-
createRemotePathResolver());
145+
getRemoteExecutionService());
133146
registryBuilder.registerStrategy(
134147
new RemoteSpawnStrategy(env.getExecRoot(), spawnRunner, verboseFailures), "remote");
135148
}
@@ -145,13 +158,8 @@ public void registerSpawnCache(ModuleActionContextRegistry.Builder registryBuild
145158
env.getExecRoot(),
146159
checkNotNull(env.getOptions().getOptions(RemoteOptions.class)),
147160
checkNotNull(env.getOptions().getOptions(ExecutionOptions.class)).verboseFailures,
148-
cache,
149-
env.getBuildRequestId(),
150-
env.getCommandId().toString(),
151161
env.getReporter(),
152-
digestUtil,
153-
filesToDownload,
154-
createRemotePathResolver());
162+
getRemoteExecutionService());
155163
registryBuilder.register(SpawnCache.class, spawnCache, "remote-cache");
156164
}
157165

0 commit comments

Comments
 (0)