diff options
author | Benjamin Peterson <bp@benjamin.pe> | 2018-05-03 04:30:19 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-03 04:32:12 -0700 |
commit | 7e1c7bcd4215a20479963ec34c8d7b685f393cc6 (patch) | |
tree | 7dd4d13f52c52cc3a41b03ebc2035840eb32969d /src/main/java/com/google/devtools/build | |
parent | 8ac2fb1ff86a8a08d1a53888ae5adf901becd2b9 (diff) |
Report what RemoteSpawnCache is doing.
Post ProgressStatus.CHECKING_CACHE if RemoteSpawnCache is checking the cache.
The UI sees CHECKING_CACHE exactly the same as EXECUTING because no UIs
currently have any special behavior for actions in cache-lookup state. This is
still a UX improvement with --experimental_spawn_cache because EXECUTING is
generally more correct than the old action state, which varies from harmless but
unhelpful (no known state) to just wrong (C++ compile actions claimed they were
doing include scanning during cache lookups).
Closes #5130.
Change-Id: I77421c3667c180875216f937fe0713f0e9415a7a
PiperOrigin-RevId: 195233123
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java | 1 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java | 69 |
2 files changed, 39 insertions, 31 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java index d9ae236622..d8c42ff140 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java @@ -252,6 +252,7 @@ public abstract class AbstractSpawnStrategy implements SandboxedSpawnActionConte EventBus eventBus = actionExecutionContext.getEventBus(); switch (state) { case EXECUTING: + case CHECKING_CACHE: eventBus.post(ActionStatusMessage.runningStrategy(action, name)); break; case SCHEDULING: diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java index 72766ced3e..2e31f83b48 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.Reporter; import com.google.devtools.build.lib.exec.SpawnCache; +import com.google.devtools.build.lib.exec.SpawnRunner.ProgressStatus; import com.google.devtools.build.lib.exec.SpawnRunner.SpawnExecutionContext; import com.google.devtools.build.lib.remote.TreeNodeRepository.TreeNode; import com.google.devtools.build.lib.remote.util.DigestUtil; @@ -91,6 +92,12 @@ final class RemoteSpawnCache implements SpawnCache { @Override public CacheHandle lookup(Spawn spawn, SpawnExecutionContext context) throws InterruptedException, IOException, ExecException { + boolean checkCache = options.remoteAcceptCached && Spawns.mayBeCached(spawn); + + if (checkCache) { + context.report(ProgressStatus.CHECKING_CACHE, "remote-cache"); + } + // Temporary hack: the TreeNodeRepository should be created and maintained upstream! TreeNodeRepository repository = new TreeNodeRepository(execRoot, context.getActionInputFileCache(), digestUtil); @@ -106,42 +113,42 @@ final class RemoteSpawnCache implements SpawnCache { spawn.getExecutionPlatform(), context.getTimeout(), Spawns.mayBeCached(spawn)); - // Look up action cache, and reuse the action output if it is found. final ActionKey actionKey = digestUtil.computeActionKey(action); + Context withMetadata = TracingMetadataUtils.contextWithMetadata(buildRequestId, commandId, actionKey); - // Metadata will be available in context.current() until we detach. - // This is done via a thread-local variable. - Context previous = withMetadata.attach(); - try { - ActionResult result = - this.options.remoteAcceptCached && Spawns.mayBeCached(spawn) - ? remoteCache.getCachedActionResult(actionKey) - : null; - if (result != null) { - // We don't cache failed actions, so we know the outputs exist. - // For now, download all outputs locally; in the future, we can reuse the digests to - // just update the TreeNodeRepository and continue the build. - remoteCache.download(result, execRoot, context.getFileOutErr()); - SpawnResult spawnResult = - new SpawnResult.Builder() - .setStatus(Status.SUCCESS) - .setExitCode(result.getExitCode()) - .setCacheHit(true) - .setRunnerName("remote cache hit") - .build(); - return SpawnCache.success(spawnResult); + + if (checkCache) { + // Metadata will be available in context.current() until we detach. + // This is done via a thread-local variable. + Context previous = withMetadata.attach(); + try { + ActionResult result = remoteCache.getCachedActionResult(actionKey); + if (result != null) { + // We don't cache failed actions, so we know the outputs exist. + // For now, download all outputs locally; in the future, we can reuse the digests to + // just update the TreeNodeRepository and continue the build. + remoteCache.download(result, execRoot, context.getFileOutErr()); + SpawnResult spawnResult = + new SpawnResult.Builder() + .setStatus(Status.SUCCESS) + .setExitCode(result.getExitCode()) + .setCacheHit(true) + .setRunnerName("remote cache hit") + .build(); + return SpawnCache.success(spawnResult); + } + } catch (CacheNotFoundException e) { + // There's a cache miss. Fall back to local execution. + } catch (IOException e) { + // There's an IO error. Fall back to local execution. + reportOnce( + Event.warn( + "Some artifacts failed to be downloaded from the remote cache: " + e.getMessage())); + } finally { + withMetadata.detach(previous); } - } catch (CacheNotFoundException e) { - // There's a cache miss. Fall back to local execution. - } catch (IOException e) { - // There's an IO error. Fall back to local execution. - reportOnce( - Event.warn( - "Some artifacts failed to be downloaded from the remote cache: " + e.getMessage())); - } finally { - withMetadata.detach(previous); } if (options.remoteUploadLocalResults) { return new CacheHandle() { |