use of build.buildfarm.common.Poller in project bazel-buildfarm by bazelbuild.
the class ShardInstance method transformAndQueue.
private ListenableFuture<Void> transformAndQueue(ExecuteEntry executeEntry, Poller poller, Operation operation, Stopwatch stopwatch, Duration timeout) {
long checkCacheUSecs = stopwatch.elapsed(MICROSECONDS);
ExecuteOperationMetadata metadata;
try {
metadata = operation.getMetadata().unpack(ExecuteOperationMetadata.class);
} catch (InvalidProtocolBufferException e) {
return immediateFailedFuture(e);
}
Digest actionDigest = metadata.getActionDigest();
SettableFuture<Void> queueFuture = SettableFuture.create();
logger.log(Level.FINE, format("ShardInstance(%s): queue(%s): fetching action %s", getName(), operation.getName(), actionDigest.getHash()));
RequestMetadata requestMetadata = executeEntry.getRequestMetadata();
ListenableFuture<Action> actionFuture = catchingAsync(transformAsync(expectAction(actionDigest, requestMetadata), (action) -> {
if (action == null) {
throw Status.NOT_FOUND.asException();
} else if (action.getDoNotCache()) {
// invalidate our action cache result as well as watcher owner
readThroughActionCache.invalidate(DigestUtil.asActionKey(actionDigest));
backplane.putOperation(operation.toBuilder().setMetadata(Any.pack(action)).build(), metadata.getStage());
}
return immediateFuture(action);
}, operationTransformService), StatusException.class, (e) -> {
Status st = Status.fromThrowable(e);
if (st.getCode() == Code.NOT_FOUND) {
PreconditionFailure.Builder preconditionFailure = PreconditionFailure.newBuilder();
preconditionFailure.addViolationsBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(actionDigest)).setDescription(MISSING_ACTION);
checkPreconditionFailure(actionDigest, preconditionFailure.build());
}
throw st.asRuntimeException();
}, operationTransformService);
QueuedOperation.Builder queuedOperationBuilder = QueuedOperation.newBuilder();
ListenableFuture<ProfiledQueuedOperationMetadata.Builder> queuedFuture = transformAsync(actionFuture, (action) -> {
logger.log(Level.FINE, format("ShardInstance(%s): queue(%s): fetched action %s transforming queuedOperation", getName(), operation.getName(), actionDigest.getHash()));
Stopwatch transformStopwatch = Stopwatch.createStarted();
return transform(transformQueuedOperation(operation.getName(), action, action.getCommandDigest(), action.getInputRootDigest(), queuedOperationBuilder, operationTransformService, requestMetadata), (queuedOperation) -> ProfiledQueuedOperationMetadata.newBuilder().setQueuedOperation(queuedOperation).setQueuedOperationMetadata(buildQueuedOperationMetadata(metadata, requestMetadata, queuedOperation)).setTransformedIn(Durations.fromMicros(transformStopwatch.elapsed(MICROSECONDS))), operationTransformService);
}, operationTransformService);
ListenableFuture<ProfiledQueuedOperationMetadata.Builder> validatedFuture = transformAsync(queuedFuture, (profiledQueuedMetadata) -> {
logger.log(Level.FINE, format("ShardInstance(%s): queue(%s): queuedOperation %s transformed, validating", getName(), operation.getName(), DigestUtil.toString(profiledQueuedMetadata.getQueuedOperationMetadata().getQueuedOperationDigest())));
long startValidateUSecs = stopwatch.elapsed(MICROSECONDS);
/* sync, throws StatusException */
validateQueuedOperation(actionDigest, profiledQueuedMetadata.getQueuedOperation());
return immediateFuture(profiledQueuedMetadata.setValidatedIn(Durations.fromMicros(stopwatch.elapsed(MICROSECONDS) - startValidateUSecs)));
}, operationTransformService);
ListenableFuture<ProfiledQueuedOperationMetadata> queuedOperationCommittedFuture = transformAsync(validatedFuture, (profiledQueuedMetadata) -> {
logger.log(Level.FINE, format("ShardInstance(%s): queue(%s): queuedOperation %s validated, uploading", getName(), operation.getName(), DigestUtil.toString(profiledQueuedMetadata.getQueuedOperationMetadata().getQueuedOperationDigest())));
ByteString queuedOperationBlob = profiledQueuedMetadata.getQueuedOperation().toByteString();
Digest queuedOperationDigest = profiledQueuedMetadata.getQueuedOperationMetadata().getQueuedOperationDigest();
long startUploadUSecs = stopwatch.elapsed(MICROSECONDS);
return transform(writeBlobFuture(queuedOperationDigest, queuedOperationBlob, requestMetadata, timeout), (committedSize) -> profiledQueuedMetadata.setUploadedIn(Durations.fromMicros(stopwatch.elapsed(MICROSECONDS) - startUploadUSecs)).build(), operationTransformService);
}, operationTransformService);
// onQueue call?
addCallback(queuedOperationCommittedFuture, new FutureCallback<ProfiledQueuedOperationMetadata>() {
@Override
public void onSuccess(ProfiledQueuedOperationMetadata profiledQueuedMetadata) {
QueuedOperationMetadata queuedOperationMetadata = profiledQueuedMetadata.getQueuedOperationMetadata();
Operation queueOperation = operation.toBuilder().setMetadata(Any.pack(queuedOperationMetadata)).build();
QueueEntry queueEntry = QueueEntry.newBuilder().setExecuteEntry(executeEntry).setQueuedOperationDigest(queuedOperationMetadata.getQueuedOperationDigest()).setPlatform(profiledQueuedMetadata.getQueuedOperation().getCommand().getPlatform()).build();
try {
ensureCanQueue(stopwatch);
long startQueueUSecs = stopwatch.elapsed(MICROSECONDS);
poller.pause();
backplane.queue(queueEntry, queueOperation);
long elapsedUSecs = stopwatch.elapsed(MICROSECONDS);
long queueUSecs = elapsedUSecs - startQueueUSecs;
logger.log(Level.FINE, format("ShardInstance(%s): queue(%s): %dus checkCache, %dus transform, %dus validate, %dus upload, %dus queue, %dus elapsed", getName(), queueOperation.getName(), checkCacheUSecs, Durations.toMicros(profiledQueuedMetadata.getTransformedIn()), Durations.toMicros(profiledQueuedMetadata.getValidatedIn()), Durations.toMicros(profiledQueuedMetadata.getUploadedIn()), queueUSecs, elapsedUSecs));
queueFuture.set(null);
} catch (IOException e) {
onFailure(e.getCause() == null ? e : e.getCause());
} catch (InterruptedException e) {
// ignore
}
}
@Override
public void onFailure(Throwable t) {
poller.pause();
com.google.rpc.Status status = StatusProto.fromThrowable(t);
if (status == null) {
logger.log(Level.SEVERE, "no rpc status from exception for " + operation.getName(), t);
status = asExecutionStatus(t);
} else if (com.google.rpc.Code.forNumber(status.getCode()) == com.google.rpc.Code.DEADLINE_EXCEEDED) {
logger.log(Level.WARNING, "an rpc status was thrown with DEADLINE_EXCEEDED for " + operation.getName() + ", discarding it", t);
status = com.google.rpc.Status.newBuilder().setCode(com.google.rpc.Code.UNAVAILABLE.getNumber()).setMessage("SUPPRESSED DEADLINE_EXCEEDED: " + t.getMessage()).build();
}
logFailedStatus(actionDigest, status);
errorOperationFuture(operation, requestMetadata, status, queueFuture);
}
}, operationTransformService);
return queueFuture;
}
use of build.buildfarm.common.Poller in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method queueActionMissingErrorsOperation.
@Test
public void queueActionMissingErrorsOperation() throws Exception {
Action action = createAction(false);
Digest actionDigest = DIGEST_UTIL.compute(action);
ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("missing-action-operation").setActionDigest(actionDigest).setSkipCacheLookup(true).build();
when(mockBackplane.canQueue()).thenReturn(true);
Poller poller = mock(Poller.class);
boolean failedPreconditionExceptionCaught = false;
try {
instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
} catch (ExecutionException e) {
com.google.rpc.Status status = StatusProto.fromThrowable(e);
if (status.getCode() == Code.FAILED_PRECONDITION.getNumber()) {
failedPreconditionExceptionCaught = true;
} else {
e.getCause().printStackTrace();
}
}
assertThat(failedPreconditionExceptionCaught).isTrue();
PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(actionDigest)).setDescription(MISSING_ACTION)).build();
ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
assertResponse(executeResponse);
verify(poller, atLeastOnce()).pause();
}
use of build.buildfarm.common.Poller in project bazel-buildfarm by bazelbuild.
the class ShardInstanceTest method queueDirectoryMissingErrorsOperation.
@Test
public void queueDirectoryMissingErrorsOperation() throws Exception {
ByteString foo = ByteString.copyFromUtf8("foo");
Digest subdirDigest = DIGEST_UTIL.compute(foo);
Directory inputRoot = Directory.newBuilder().addDirectories(DirectoryNode.newBuilder().setName("missing-subdir").setDigest(subdirDigest)).build();
ByteString inputRootContent = inputRoot.toByteString();
Digest inputRootDigest = DIGEST_UTIL.compute(inputRootContent);
provideBlob(inputRootDigest, inputRootContent);
Action action = createAction(true, true, inputRootDigest, SIMPLE_COMMAND);
Digest actionDigest = DIGEST_UTIL.compute(action);
ExecuteEntry executeEntry = ExecuteEntry.newBuilder().setOperationName("missing-directory-operation").setActionDigest(actionDigest).setSkipCacheLookup(true).build();
when(mockBackplane.propertiesEligibleForQueue(Matchers.anyList())).thenReturn(true);
when(mockBackplane.canQueue()).thenReturn(true);
Poller poller = mock(Poller.class);
boolean failedPreconditionExceptionCaught = false;
try {
instance.queue(executeEntry, poller, DEFAULT_TIMEOUT).get(QUEUE_TEST_TIMEOUT_SECONDS, SECONDS);
} catch (ExecutionException e) {
com.google.rpc.Status status = StatusProto.fromThrowable(e);
if (status.getCode() == Code.FAILED_PRECONDITION.getNumber()) {
failedPreconditionExceptionCaught = true;
} else {
e.getCause().printStackTrace();
}
}
assertThat(failedPreconditionExceptionCaught).isTrue();
PreconditionFailure preconditionFailure = PreconditionFailure.newBuilder().addViolations(Violation.newBuilder().setType(VIOLATION_TYPE_MISSING).setSubject("blobs/" + DigestUtil.toString(subdirDigest)).setDescription("The directory `/missing-subdir` was not found in the CAS.")).build();
ExecuteResponse executeResponse = ExecuteResponse.newBuilder().setStatus(com.google.rpc.Status.newBuilder().setCode(Code.FAILED_PRECONDITION.getNumber()).setMessage(invalidActionVerboseMessage(actionDigest, preconditionFailure)).addDetails(Any.pack(preconditionFailure))).build();
assertResponse(executeResponse);
verify(poller, atLeastOnce()).pause();
}
use of build.buildfarm.common.Poller 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.Poller 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();
}
Aggregations