Skip to content

Commit 716b527

Browse files
ulfjackphilwo
authored andcommitted
Only create a single per-build instance of the remote cache / executor
Fixes bazelbuild#3189. Fixes bazelbuild#2823. PiperOrigin-RevId: 159699146
1 parent 33d05f6 commit 716b527

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

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

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ final class RemoteSpawnStrategy implements SpawnActionContext {
7373
private final ChannelOptions channelOptions;
7474
private final SpawnInputExpander spawnInputExpander = new SpawnInputExpander(/*strict=*/ false);
7575

76+
private final RemoteActionCache remoteCache;
77+
private final GrpcRemoteExecutor workExecutor;
78+
7679
RemoteSpawnStrategy(
7780
Path execRoot,
7881
RemoteOptions remoteOptions,
@@ -97,6 +100,30 @@ final class RemoteSpawnStrategy implements SpawnActionContext {
97100
} else {
98101
platform = null;
99102
}
103+
// Initialize remote cache and execution handlers. We use separate handlers for every
104+
// action to enable server-side parallelism (need a different gRPC channel per action).
105+
if (SimpleBlobStoreFactory.isRemoteCacheOptions(remoteOptions)) {
106+
remoteCache = new SimpleBlobStoreActionCache(SimpleBlobStoreFactory.create(remoteOptions));
107+
} else if (GrpcActionCache.isRemoteCacheOptions(remoteOptions)) {
108+
remoteCache =
109+
new GrpcActionCache(
110+
RemoteUtils.createChannel(remoteOptions.remoteCache, channelOptions),
111+
channelOptions,
112+
remoteOptions);
113+
} else {
114+
remoteCache = null;
115+
}
116+
// Otherwise remoteCache remains null and remote caching/execution are disabled.
117+
118+
if (remoteCache != null && GrpcRemoteExecutor.isRemoteExecutionOptions(remoteOptions)) {
119+
workExecutor =
120+
new GrpcRemoteExecutor(
121+
RemoteUtils.createChannel(remoteOptions.remoteExecutor, channelOptions),
122+
channelOptions,
123+
remoteOptions);
124+
} else {
125+
workExecutor = null;
126+
}
100127
}
101128

102129
private Action buildAction(
@@ -221,30 +248,6 @@ public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext)
221248
String mnemonic = spawn.getMnemonic();
222249
EventHandler eventHandler = actionExecutionContext.getEventHandler();
223250

224-
RemoteActionCache remoteCache = null;
225-
GrpcRemoteExecutor workExecutor = null;
226-
if (spawn.isRemotable()) {
227-
// Initialize remote cache and execution handlers. We use separate handlers for every
228-
// action to enable server-side parallelism (need a different gRPC channel per action).
229-
if (SimpleBlobStoreFactory.isRemoteCacheOptions(remoteOptions)) {
230-
remoteCache = new SimpleBlobStoreActionCache(SimpleBlobStoreFactory.create(remoteOptions));
231-
} else if (GrpcActionCache.isRemoteCacheOptions(remoteOptions)) {
232-
remoteCache =
233-
new GrpcActionCache(
234-
RemoteUtils.createChannel(remoteOptions.remoteCache, channelOptions),
235-
channelOptions,
236-
remoteOptions);
237-
}
238-
// Otherwise remoteCache remains null and remote caching/execution are disabled.
239-
240-
if (remoteCache != null && GrpcRemoteExecutor.isRemoteExecutionOptions(remoteOptions)) {
241-
workExecutor =
242-
new GrpcRemoteExecutor(
243-
RemoteUtils.createChannel(remoteOptions.remoteExecutor, channelOptions),
244-
channelOptions,
245-
remoteOptions);
246-
}
247-
}
248251
if (!spawn.isRemotable() || remoteCache == null) {
249252
fallbackStrategy.exec(spawn, actionExecutionContext);
250253
return;

0 commit comments

Comments
 (0)