diff options
author | 2017-03-02 17:32:28 +0000 | |
---|---|---|
committer | 2017-03-03 10:36:39 +0000 | |
commit | cddaaa66b9aac7c4ea4772ae2a23b97426d267c2 (patch) | |
tree | eb018b744eff97144ccc2fb3850dfc184b907236 /src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java | |
parent | 64f3eb0492f675d0e4713989f2bdd175ff078758 (diff) |
Rationalize local resource acquisition
Move all local resource acquisition to where local execution actually happens.
Don't attempt to acquire resources per action, but only for individual spawns.
This significantly simplifies the code.
The downside is that we don't account for action-level work anymore. In
general, actions should not perform any process execution themselves, but
always delegate such work to a SpawnStrategy implementation.
This change makes sure that every Spawn has local resources set in a way that
is consistent with the previous state.
However, there are two actions - Fileset and FileWrite -, which are not spawns,
and so we now don't limit their concurrent execution anymore. For Fileset, all
work is done in a custom Fileset-specific thread pool, so this shouldn't be a
problem. I'm not sure about FileWriteAction.
--
PiperOrigin-RevId: 149012600
MOS_MIGRATED_REVID=149012600
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java index dab387db1d..a0fadc8722 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java @@ -22,8 +22,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; +import com.google.common.eventbus.EventBus; import com.google.common.hash.HashCode; import com.google.devtools.build.lib.actions.ActionExecutionContext; +import com.google.devtools.build.lib.actions.ActionExecutionMetadata; import com.google.devtools.build.lib.actions.ActionInput; import com.google.devtools.build.lib.actions.ActionInputFileCache; import com.google.devtools.build.lib.actions.ActionInputHelper; @@ -31,6 +33,8 @@ import com.google.devtools.build.lib.actions.ActionStatusMessage; import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.actions.ExecutionStrategy; import com.google.devtools.build.lib.actions.Executor; +import com.google.devtools.build.lib.actions.ResourceManager; +import com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle; import com.google.devtools.build.lib.actions.SandboxedSpawnActionContext; import com.google.devtools.build.lib.actions.Spawn; import com.google.devtools.build.lib.actions.SpawnActionContext; @@ -204,23 +208,39 @@ public final class WorkerSpawnStrategy implements SandboxedSpawnActionContext { AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException { Executor executor = actionExecutionContext.getExecutor(); - EventHandler eventHandler = executor.getEventHandler(); - StandaloneSpawnStrategy standaloneStrategy = - Preconditions.checkNotNull(executor.getContext(StandaloneSpawnStrategy.class)); - - if (executor.reportsSubcommands()) { - executor.reportSubcommand(spawn); - } - if (!spawn.getExecutionInfo().containsKey("supports-workers") || !spawn.getExecutionInfo().get("supports-workers").equals("1")) { - eventHandler.handle( + StandaloneSpawnStrategy standaloneStrategy = + Preconditions.checkNotNull(executor.getContext(StandaloneSpawnStrategy.class)); + executor.getEventHandler().handle( Event.warn( String.format(ERROR_MESSAGE_PREFIX + REASON_NO_EXECUTION_INFO, spawn.getMnemonic()))); standaloneStrategy.exec(spawn, actionExecutionContext); return; } + EventBus eventBus = actionExecutionContext.getExecutor().getEventBus(); + ActionExecutionMetadata owner = spawn.getResourceOwner(); + eventBus.post(ActionStatusMessage.schedulingStrategy(owner)); + try (ResourceHandle handle = + ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) { + eventBus.post(ActionStatusMessage.runningStrategy(spawn.getResourceOwner(), "worker")); + actuallyExec(spawn, actionExecutionContext, writeOutputFiles); + } + } + + private void actuallyExec( + Spawn spawn, + ActionExecutionContext actionExecutionContext, + AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) + throws ExecException, InterruptedException { + Executor executor = actionExecutionContext.getExecutor(); + EventHandler eventHandler = executor.getEventHandler(); + + if (executor.reportsSubcommands()) { + executor.reportSubcommand(spawn); + } + // We assume that the spawn to be executed always gets a @flagfile argument, which contains the // flags related to the work itself (as opposed to start-up options for the executed tool). // Thus, we can extract the last element from its args (which will be the @flagfile), expand it @@ -235,10 +255,6 @@ public final class WorkerSpawnStrategy implements SandboxedSpawnActionContext { String.format(ERROR_MESSAGE_PREFIX + REASON_NO_TOOLS, spawn.getMnemonic())); } - executor - .getEventBus() - .post(ActionStatusMessage.runningStrategy(spawn.getResourceOwner(), "worker")); - FileOutErr outErr = actionExecutionContext.getFileOutErr(); ImmutableList<String> args = |