Skip to content

Commit

Permalink
Only create a single per-build instance of the remote cache / executor
Browse files Browse the repository at this point in the history
Fixes #3189.
Fixes #2823.

PiperOrigin-RevId: 159699146
  • Loading branch information
ulfjack authored and philwo committed Jun 22, 2017
1 parent 33d05f6 commit 716b527
Showing 1 changed file with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ final class RemoteSpawnStrategy implements SpawnActionContext {
private final ChannelOptions channelOptions;
private final SpawnInputExpander spawnInputExpander = new SpawnInputExpander(/*strict=*/ false);

private final RemoteActionCache remoteCache;
private final GrpcRemoteExecutor workExecutor;

RemoteSpawnStrategy(
Path execRoot,
RemoteOptions remoteOptions,
Expand All @@ -97,6 +100,30 @@ final class RemoteSpawnStrategy implements SpawnActionContext {
} else {
platform = null;
}
// Initialize remote cache and execution handlers. We use separate handlers for every
// action to enable server-side parallelism (need a different gRPC channel per action).
if (SimpleBlobStoreFactory.isRemoteCacheOptions(remoteOptions)) {
remoteCache = new SimpleBlobStoreActionCache(SimpleBlobStoreFactory.create(remoteOptions));
} else if (GrpcActionCache.isRemoteCacheOptions(remoteOptions)) {
remoteCache =
new GrpcActionCache(
RemoteUtils.createChannel(remoteOptions.remoteCache, channelOptions),
channelOptions,
remoteOptions);
} else {
remoteCache = null;
}
// Otherwise remoteCache remains null and remote caching/execution are disabled.

if (remoteCache != null && GrpcRemoteExecutor.isRemoteExecutionOptions(remoteOptions)) {
workExecutor =
new GrpcRemoteExecutor(
RemoteUtils.createChannel(remoteOptions.remoteExecutor, channelOptions),
channelOptions,
remoteOptions);
} else {
workExecutor = null;
}
}

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

RemoteActionCache remoteCache = null;
GrpcRemoteExecutor workExecutor = null;
if (spawn.isRemotable()) {
// Initialize remote cache and execution handlers. We use separate handlers for every
// action to enable server-side parallelism (need a different gRPC channel per action).
if (SimpleBlobStoreFactory.isRemoteCacheOptions(remoteOptions)) {
remoteCache = new SimpleBlobStoreActionCache(SimpleBlobStoreFactory.create(remoteOptions));
} else if (GrpcActionCache.isRemoteCacheOptions(remoteOptions)) {
remoteCache =
new GrpcActionCache(
RemoteUtils.createChannel(remoteOptions.remoteCache, channelOptions),
channelOptions,
remoteOptions);
}
// Otherwise remoteCache remains null and remote caching/execution are disabled.

if (remoteCache != null && GrpcRemoteExecutor.isRemoteExecutionOptions(remoteOptions)) {
workExecutor =
new GrpcRemoteExecutor(
RemoteUtils.createChannel(remoteOptions.remoteExecutor, channelOptions),
channelOptions,
remoteOptions);
}
}
if (!spawn.isRemotable() || remoteCache == null) {
fallbackStrategy.exec(spawn, actionExecutionContext);
return;
Expand Down

0 comments on commit 716b527

Please sign in to comment.