use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.
the class ShardInstance method requeueOperation.
@VisibleForTesting
public ListenableFuture<Void> requeueOperation(QueueEntry queueEntry, Duration timeout) {
ListenableFuture<Void> future;
ExecuteEntry executeEntry = queueEntry.getExecuteEntry();
Operation operation = getOperation(executeEntry.getOperationName());
try {
// check preconditions before trying to requeue.
boolean canRequeue = canOperationBeRequeued(queueEntry, executeEntry, operation);
if (!canRequeue) {
return IMMEDIATE_VOID_FUTURE;
}
// Requeue the action as long as the result is not already cached.
ActionKey actionKey = DigestUtil.asActionKey(executeEntry.getActionDigest());
ListenableFuture<Boolean> cachedResultFuture;
if (executeEntry.getSkipCacheLookup()) {
cachedResultFuture = immediateFuture(false);
} else {
cachedResultFuture = checkCacheFuture(actionKey, operation, executeEntry.getRequestMetadata());
}
future = transformAsync(cachedResultFuture, (cachedResult) -> {
if (cachedResult) {
return IMMEDIATE_VOID_FUTURE;
}
return validateAndRequeueOperation(operation, queueEntry, timeout);
}, operationTransformService);
} catch (IOException | StatusRuntimeException e) {
return immediateFailedFuture(e);
}
return future;
}
use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.
the class ShardInstance method queue.
@VisibleForTesting
public ListenableFuture<Void> queue(ExecuteEntry executeEntry, Poller poller, Duration timeout) {
ExecuteOperationMetadata metadata = ExecuteOperationMetadata.newBuilder().setActionDigest(executeEntry.getActionDigest()).setStdoutStreamName(executeEntry.getStdoutStreamName()).setStderrStreamName(executeEntry.getStderrStreamName()).build();
Operation operation = Operation.newBuilder().setName(executeEntry.getOperationName()).setMetadata(Any.pack(metadata)).build();
Digest actionDigest = executeEntry.getActionDigest();
ActionKey actionKey = DigestUtil.asActionKey(actionDigest);
Stopwatch stopwatch = Stopwatch.createStarted();
ListenableFuture<Boolean> cachedResultFuture;
if (executeEntry.getSkipCacheLookup()) {
cachedResultFuture = immediateFuture(false);
} else {
cachedResultFuture = checkCacheFuture(actionKey, operation, executeEntry.getRequestMetadata());
}
return transformAsync(cachedResultFuture, (cachedResult) -> {
if (cachedResult) {
poller.pause();
long checkCacheUSecs = stopwatch.elapsed(MICROSECONDS);
logger.log(Level.FINE, format("ShardInstance(%s): checkCache(%s): %sus elapsed", getName(), operation.getName(), checkCacheUSecs));
return IMMEDIATE_VOID_FUTURE;
}
return transformAndQueue(executeEntry, poller, operation, stopwatch, timeout);
}, operationTransformService);
}
use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method duplicateExecutionsServedFromCacheAreForcedToSkipLookup.
@Test
public void duplicateExecutionsServedFromCacheAreForcedToSkipLookup() throws Exception {
ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
ActionResult actionResult = ActionResult.newBuilder().addOutputFiles(OutputFile.newBuilder().setPath("does-not-exist").setDigest(Digest.newBuilder().setHash("dne").setSizeBytes(1))).setStdoutDigest(Digest.newBuilder().setHash("stdout").setSizeBytes(1)).setStderrDigest(Digest.newBuilder().setHash("stderr").setSizeBytes(1)).build();
when(mockBackplane.canQueue()).thenReturn(true);
when(mockBackplane.canPrequeue()).thenReturn(true);
when(mockBackplane.getActionResult(actionKey)).thenReturn(actionResult);
Digest actionDigest = actionKey.getDigest();
RequestMetadata requestMetadata = RequestMetadata.newBuilder().setToolDetails(ToolDetails.newBuilder().setToolName("buildfarm-test").setToolVersion("0.1")).setCorrelatedInvocationsId(UUID.randomUUID().toString()).setToolInvocationId(UUID.randomUUID().toString()).setActionId(actionDigest.getHash()).build();
String operationName = "cache-served-operation";
ExecuteEntry cacheServedExecuteEntry = ExecuteEntry.newBuilder().setOperationName(operationName).setActionDigest(actionDigest).setRequestMetadata(requestMetadata).build();
Poller poller = mock(Poller.class);
instance.queue(cacheServedExecuteEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
verify(poller, times(1)).pause();
verify(mockBackplane, never()).queue(any(QueueEntry.class), any(Operation.class));
ArgumentCaptor<Operation> cacheCheckOperationCaptor = ArgumentCaptor.forClass(Operation.class);
verify(mockBackplane, times(1)).putOperation(cacheCheckOperationCaptor.capture(), eq(CACHE_CHECK));
Operation cacheCheckOperation = cacheCheckOperationCaptor.getValue();
assertThat(cacheCheckOperation.getName()).isEqualTo(operationName);
ArgumentCaptor<Operation> completedOperationCaptor = ArgumentCaptor.forClass(Operation.class);
verify(mockBackplane, times(1)).putOperation(completedOperationCaptor.capture(), eq(COMPLETED));
Operation completedOperation = completedOperationCaptor.getValue();
assertThat(completedOperation.getName()).isEqualTo(operationName);
ExecuteResponse executeResponse = completedOperation.getResponse().unpack(ExecuteResponse.class);
assertThat(executeResponse.getResult()).isEqualTo(actionResult);
assertThat(executeResponse.getCachedResult()).isTrue();
Watcher mockWatcher = mock(Watcher.class);
instance.execute(actionDigest, /* skipCacheLookup=*/
false, ExecutionPolicy.getDefaultInstance(), ResultsCachePolicy.getDefaultInstance(), requestMetadata, /* watcher=*/
mockWatcher);
verify(mockWatcher, times(1)).observe(any(Operation.class));
ArgumentCaptor<ExecuteEntry> executeEntryCaptor = ArgumentCaptor.forClass(ExecuteEntry.class);
verify(mockBackplane, times(1)).prequeue(executeEntryCaptor.capture(), any(Operation.class));
ExecuteEntry executeEntry = executeEntryCaptor.getValue();
assertThat(executeEntry.getSkipCacheLookup()).isTrue();
}
use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method queueWithFailedCacheCheckContinues.
@Test
public void queueWithFailedCacheCheckContinues() throws Exception {
Action action = createAction();
ActionKey actionKey = DIGEST_UTIL.computeActionKey(action);
ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("operation-with-erroring-action-result").setActionDigest(actionKey.getDigest()).build();
when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(true);
when(mockBackplane.canQueue()).thenReturn(true);
when(mockBackplane.getActionResult(eq(actionKey))).thenThrow(new IOException(Status.UNAVAILABLE.asException()));
doAnswer(answer((digest, uuid) -> new NullWrite())).when(mockWorkerInstance).getBlobWrite(any(Digest.class), any(UUID.class), any(RequestMetadata.class));
Poller poller = mock(Poller.class);
instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
verify(mockBackplane, times(1)).queue(any(QueueEntry.class), any(Operation.class));
verify(mockBackplane, times(1)).putOperation(any(Operation.class), eq(CACHE_CHECK));
verify(poller, atLeastOnce()).pause();
}
use of build.buildfarm.common.DigestUtil.ActionKey in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method actionResultWatcherDiscardsUncacheableResult.
@Test
public void actionResultWatcherDiscardsUncacheableResult() throws Exception {
ActionKey actionKey = DigestUtil.asActionKey(Digest.newBuilder().setHash("test").build());
Watcher mockWatcher = mock(Watcher.class);
Watcher actionResultWatcher = instance.newActionResultWatcher(actionKey, mockWatcher);
Action uncacheableAction = Action.newBuilder().setDoNotCache(true).build();
Operation operation = Operation.newBuilder().setMetadata(Any.pack(uncacheableAction)).build();
ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setCachedResult(true).build();
Operation completedOperation = Operation.newBuilder().setDone(true).setResponse(Any.pack(executeResponse)).build();
actionResultWatcher.observe(operation);
actionResultWatcher.observe(completedOperation);
verify(mockWatcher, never()).observe(operation);
ListenableFuture<ActionResult> resultFuture = instance.getActionResult(actionKey, RequestMetadata.getDefaultInstance());
ActionResult result = resultFuture.get();
assertThat(result).isNull();
verify(mockWatcher, times(1)).observe(completedOperation);
}
Aggregations