Search in sources :

Example 11 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class ShardInstance method findMissingBlobs.

@Override
public ListenableFuture<Iterable<Digest>> findMissingBlobs(Iterable<Digest> blobDigests, RequestMetadata requestMetadata) {
    try {
        if (inDenyList(requestMetadata)) {
            // TODO change this back to a transient when #10663 is landed
            return immediateFuture(ImmutableList.of());
        /*
        return immediateFailedFuture(Status.UNAVAILABLE
            .withDescription("The action associated with this request is forbidden")
            .asException());
            */
        }
    } catch (IOException e) {
        return immediateFailedFuture(Status.fromThrowable(e).asException());
    }
    Iterable<Digest> nonEmptyDigests = Iterables.filter(blobDigests, (digest) -> digest.getSizeBytes() > 0);
    if (Iterables.isEmpty(nonEmptyDigests)) {
        return immediateFuture(ImmutableList.of());
    }
    Deque<String> workers;
    try {
        Set<String> workerSet = backplane.getWorkers();
        List<String> workersList;
        synchronized (workerSet) {
            workersList = new ArrayList<>(workerSet);
        }
        Collections.shuffle(workersList, rand);
        workers = new ArrayDeque(workersList);
    } catch (IOException e) {
        return immediateFailedFuture(Status.fromThrowable(e).asException());
    }
    if (workers.isEmpty()) {
        return immediateFuture(nonEmptyDigests);
    }
    SettableFuture<Iterable<Digest>> missingDigestsFuture = SettableFuture.create();
    findMissingBlobsOnWorker(UUID.randomUUID().toString(), nonEmptyDigests, workers, ImmutableList.builder(), Iterables.size(nonEmptyDigests), Context.current().fixedContextExecutor(directExecutor()), missingDigestsFuture, requestMetadata);
    return missingDigestsFuture;
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) IOException(java.io.IOException) ByteString(com.google.protobuf.ByteString) ArrayDeque(java.util.ArrayDeque)

Example 12 with Digest

use of com.google.cloud.kms.v1.Digest 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);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) Stopwatch(com.google.common.base.Stopwatch) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 13 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class ShardInstance method uploadQueuedOperation.

private ListenableFuture<QueuedOperationResult> uploadQueuedOperation(QueuedOperation queuedOperation, ExecuteEntry executeEntry, ExecutorService service, Duration timeout) throws EntryLimitException {
    ByteString queuedOperationBlob = queuedOperation.toByteString();
    Digest queuedOperationDigest = getDigestUtil().compute(queuedOperationBlob);
    QueuedOperationMetadata metadata = QueuedOperationMetadata.newBuilder().setExecuteOperationMetadata(executeOperationMetadata(executeEntry, ExecutionStage.Value.QUEUED)).setQueuedOperationDigest(queuedOperationDigest).build();
    QueueEntry entry = QueueEntry.newBuilder().setExecuteEntry(executeEntry).setQueuedOperationDigest(queuedOperationDigest).setPlatform(queuedOperation.getCommand().getPlatform()).build();
    return transform(writeBlobFuture(queuedOperationDigest, queuedOperationBlob, executeEntry.getRequestMetadata(), timeout), (committedSize) -> new QueuedOperationResult(entry, metadata), service);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) QueuedOperationMetadata(build.buildfarm.v1test.QueuedOperationMetadata) ProfiledQueuedOperationMetadata(build.buildfarm.v1test.ProfiledQueuedOperationMetadata) QueueEntry(build.buildfarm.v1test.QueueEntry)

Example 14 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class ShardInstance method getTreeFuture.

@Override
protected ListenableFuture<Tree> getTreeFuture(String reason, Digest inputRoot, ExecutorService service, RequestMetadata requestMetadata) {
    SettableFuture<Void> future = SettableFuture.create();
    Tree.Builder tree = Tree.newBuilder().setRootDigest(inputRoot);
    Set<Digest> digests = Sets.newConcurrentHashSet();
    Queue<Digest> remaining = new ConcurrentLinkedQueue();
    remaining.offer(inputRoot);
    Context ctx = Context.current();
    TreeCallback callback = new TreeCallback(future) {

        @Override
        protected void onDirectory(Digest digest, Directory directory) {
            tree.putDirectories(digest.getHash(), directory);
            for (DirectoryNode childNode : directory.getDirectoriesList()) {
                Digest child = childNode.getDigest();
                if (digests.add(child)) {
                    remaining.offer(child);
                }
            }
        }

        @Override
        boolean next() {
            Digest nextDigest = remaining.poll();
            if (!future.isDone() && nextDigest != null) {
                ctx.run(() -> addCallback(transform(expectDirectory(reason, nextDigest, requestMetadata), directory -> new DirectoryEntry(nextDigest, directory), service), this, service));
                return true;
            }
            return false;
        }
    };
    callback.next();
    return transform(future, (result) -> tree.build(), service);
}
Also used : Context(io.grpc.Context) Digest(build.bazel.remote.execution.v2.Digest) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) DirectoryEntry(build.buildfarm.common.TreeIterator.DirectoryEntry) Tree(build.buildfarm.v1test.Tree) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Directory(build.bazel.remote.execution.v2.Directory)

Example 15 with Digest

use of com.google.cloud.kms.v1.Digest in project bazel-buildfarm by bazelbuild.

the class ShardInstance method validateAndRequeueOperation.

private ListenableFuture<Void> validateAndRequeueOperation(Operation operation, QueueEntry queueEntry, Duration timeout) {
    ExecuteEntry executeEntry = queueEntry.getExecuteEntry();
    String operationName = executeEntry.getOperationName();
    checkState(operationName.equals(operation.getName()));
    RequestMetadata requestMetadata = executeEntry.getRequestMetadata();
    ListenableFuture<QueuedOperation> fetchQueuedOperationFuture = expect(queueEntry.getQueuedOperationDigest(), QueuedOperation.parser(), operationTransformService, requestMetadata);
    Digest actionDigest = executeEntry.getActionDigest();
    ListenableFuture<QueuedOperation> queuedOperationFuture = catchingAsync(fetchQueuedOperationFuture, Throwable.class, (e) -> buildQueuedOperation(operation.getName(), actionDigest, operationTransformService, requestMetadata), directExecutor());
    PreconditionFailure.Builder preconditionFailure = PreconditionFailure.newBuilder();
    ListenableFuture<QueuedOperation> validatedFuture = transformAsync(queuedOperationFuture, (queuedOperation) -> {
        /* sync, throws StatusException - must be serviced via non-OTS */
        validateQueuedOperationAndInputs(actionDigest, queuedOperation, preconditionFailure, requestMetadata);
        return immediateFuture(queuedOperation);
    }, operationTransformService);
    // this little fork ensures that a successfully fetched QueuedOperation
    // will not be reuploaded
    ListenableFuture<QueuedOperationResult> uploadedFuture = transformAsync(validatedFuture, (queuedOperation) -> catchingAsync(transform(fetchQueuedOperationFuture, (fechedQueuedOperation) -> {
        QueuedOperationMetadata metadata = QueuedOperationMetadata.newBuilder().setExecuteOperationMetadata(executeOperationMetadata(executeEntry, ExecutionStage.Value.QUEUED)).setQueuedOperationDigest(queueEntry.getQueuedOperationDigest()).setRequestMetadata(requestMetadata).build();
        return new QueuedOperationResult(queueEntry, metadata);
    }, operationTransformService), Throwable.class, (e) -> uploadQueuedOperation(queuedOperation, executeEntry, operationTransformService, timeout), operationTransformService), directExecutor());
    SettableFuture<Void> requeuedFuture = SettableFuture.create();
    addCallback(uploadedFuture, new FutureCallback<QueuedOperationResult>() {

        @Override
        public void onSuccess(QueuedOperationResult result) {
            Operation queueOperation = operation.toBuilder().setMetadata(Any.pack(result.metadata)).build();
            try {
                backplane.queue(result.entry, queueOperation);
                requeuedFuture.set(null);
            } catch (IOException e) {
                onFailure(e);
            }
        }

        @Override
        public void onFailure(Throwable t) {
            logger.log(Level.SEVERE, "failed to requeue: " + operationName, t);
            com.google.rpc.Status status = StatusProto.fromThrowable(t);
            if (status == null) {
                logger.log(Level.SEVERE, "no rpc status from exception for " + operationName, 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 " + operationName + ", 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);
            SettableFuture<Void> errorFuture = SettableFuture.create();
            errorOperationFuture(operation, requestMetadata, status, errorFuture);
            errorFuture.addListener(() -> requeuedFuture.set(null), operationTransformService);
        }
    }, operationTransformService);
    return requeuedFuture;
}
Also used : ExecuteOperationMetadata(build.bazel.remote.execution.v2.ExecuteOperationMetadata) AsyncCache(com.github.benmanes.caffeine.cache.AsyncCache) LoadingCache(com.google.common.cache.LoadingCache) DirectoryNode(build.bazel.remote.execution.v2.DirectoryNode) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) ExecutionStage(build.bazel.remote.execution.v2.ExecutionStage) Durations(com.google.protobuf.util.Durations) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) StatusProto(io.grpc.protobuf.StatusProto) Tree(build.buildfarm.v1test.Tree) Map(java.util.Map) Status(io.grpc.Status) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Futures.allAsList(com.google.common.util.concurrent.Futures.allAsList) EntryLimitException(build.buildfarm.common.EntryLimitException) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) MatchListener(build.buildfarm.instance.MatchListener) AbstractServerInstance(build.buildfarm.instance.server.AbstractServerInstance) VIOLATION_TYPE_MISSING(build.buildfarm.common.Errors.VIOLATION_TYPE_MISSING) DirectoryEntry(build.buildfarm.common.TreeIterator.DirectoryEntry) OperationIteratorToken(build.buildfarm.v1test.OperationIteratorToken) QueueEntry(build.buildfarm.v1test.QueueEntry) Any(com.google.protobuf.Any) MICROSECONDS(java.util.concurrent.TimeUnit.MICROSECONDS) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Actions.checkPreconditionFailure(build.buildfarm.common.Actions.checkPreconditionFailure) Directory(build.bazel.remote.execution.v2.Directory) ShardInstanceConfig(build.buildfarm.v1test.ShardInstanceConfig) Iterables(com.google.common.collect.Iterables) Command(build.bazel.remote.execution.v2.Command) MINUTES(java.util.concurrent.TimeUnit.MINUTES) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Util.correctMissingBlob(build.buildfarm.instance.shard.Util.correctMissingBlob) ResultsCachePolicy(build.bazel.remote.execution.v2.ResultsCachePolicy) Cache(com.github.benmanes.caffeine.cache.Cache) Supplier(java.util.function.Supplier) DigestUtil(build.buildfarm.common.DigestUtil) ArrayList(java.util.ArrayList) Code(io.grpc.Status.Code) Action(build.bazel.remote.execution.v2.Action) UniformDelegateServerCallStreamObserver(build.buildfarm.common.grpc.UniformDelegateServerCallStreamObserver) Futures.addCallback(com.google.common.util.concurrent.Futures.addCallback) Actions.asExecutionStatus(build.buildfarm.common.Actions.asExecutionStatus) Watcher(build.buildfarm.common.Watcher) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) VIOLATION_TYPE_INVALID(build.buildfarm.common.Errors.VIOLATION_TYPE_INVALID) Nullable(javax.annotation.Nullable) Backplane(build.buildfarm.backplane.Backplane) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) BaseEncoding(com.google.common.io.BaseEncoding) Executor(java.util.concurrent.Executor) Poller(build.buildfarm.common.Poller) Throwables(com.google.common.base.Throwables) PreconditionFailure(com.google.rpc.PreconditionFailure) IOException(java.io.IOException) QueueStatus(build.buildfarm.v1test.QueueStatus) FutureCallback(com.google.common.util.concurrent.FutureCallback) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) Duration(com.google.protobuf.Duration) FutureConverter.toCompletableFuture(net.javacrumbs.futureconverter.java8guava.FutureConverter.toCompletableFuture) ExecuteResponse(build.bazel.remote.execution.v2.ExecuteResponse) ArrayDeque(java.util.ArrayDeque) Futures.transform(com.google.common.util.concurrent.Futures.transform) Context(io.grpc.Context) Futures.transformAsync(com.google.common.util.concurrent.Futures.transformAsync) BiFunction(java.util.function.BiFunction) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Random(java.util.Random) Actions.invalidActionVerboseMessage(build.buildfarm.common.Actions.invalidActionVerboseMessage) ActionKey(build.buildfarm.common.DigestUtil.ActionKey) SettableFuture(com.google.common.util.concurrent.SettableFuture) ExecutionProperties(build.buildfarm.common.ExecutionProperties) TokenizableIterator(build.buildfarm.common.TokenizableIterator) Digest(build.bazel.remote.execution.v2.Digest) CasIndexResults(build.buildfarm.common.CasIndexResults) Gauge(io.prometheus.client.Gauge) Histogram(io.prometheus.client.Histogram) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Timestamps(com.google.protobuf.util.Timestamps) BackplaneStatus(build.buildfarm.v1test.BackplaneStatus) UUID(java.util.UUID) Logger(java.util.logging.Logger) Platform(build.bazel.remote.execution.v2.Platform) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) String.format(java.lang.String.format) Instance(build.buildfarm.instance.Instance) Sets(com.google.common.collect.Sets) Parser(com.google.protobuf.Parser) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ByteString(com.google.protobuf.ByteString) QueuedOperationMetadata(build.buildfarm.v1test.QueuedOperationMetadata) List(java.util.List) Queue(java.util.Queue) FutureConverter.toListenableFuture(net.javacrumbs.futureconverter.java8guava.FutureConverter.toListenableFuture) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) GetClientStartTimeRequest(build.buildfarm.v1test.GetClientStartTimeRequest) TreeIterator(build.buildfarm.common.TreeIterator) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Deadline(io.grpc.Deadline) Property(build.bazel.remote.execution.v2.Platform.Property) Stopwatch(com.google.common.base.Stopwatch) StatusException(io.grpc.StatusException) ProfiledQueuedOperationMetadata(build.buildfarm.v1test.ProfiledQueuedOperationMetadata) CompletableFuture(java.util.concurrent.CompletableFuture) ConfigurationException(javax.naming.ConfigurationException) Operation(com.google.longrunning.Operation) Deque(java.util.Deque) Counter(io.prometheus.client.Counter) Level(java.util.logging.Level) SHARD_IS_RETRIABLE(build.buildfarm.instance.shard.Util.SHARD_IS_RETRIABLE) ImmutableList(com.google.common.collect.ImmutableList) GetClientStartTimeResult(build.buildfarm.v1test.GetClientStartTimeResult) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) FindOperationsResults(build.buildfarm.operations.FindOperationsResults) ActionResult(build.bazel.remote.execution.v2.ActionResult) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) Futures.catching(com.google.common.util.concurrent.Futures.catching) ExecutionPolicy(build.bazel.remote.execution.v2.ExecutionPolicy) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) Write(build.buildfarm.common.Write) Futures.catchingAsync(com.google.common.util.concurrent.Futures.catchingAsync) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Futures.immediateFailedFuture(com.google.common.util.concurrent.Futures.immediateFailedFuture) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InputStream(java.io.InputStream) Status(io.grpc.Status) Actions.asExecutionStatus(build.buildfarm.common.Actions.asExecutionStatus) QueueStatus(build.buildfarm.v1test.QueueStatus) BackplaneStatus(build.buildfarm.v1test.BackplaneStatus) SettableFuture(com.google.common.util.concurrent.SettableFuture) Digest(build.bazel.remote.execution.v2.Digest) ExecuteEntry(build.buildfarm.v1test.ExecuteEntry) ByteString(com.google.protobuf.ByteString) QueuedOperation(build.buildfarm.v1test.QueuedOperation) Operation(com.google.longrunning.Operation) IOException(java.io.IOException) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Actions.checkPreconditionFailure(build.buildfarm.common.Actions.checkPreconditionFailure) PreconditionFailure(com.google.rpc.PreconditionFailure) QueuedOperation(build.buildfarm.v1test.QueuedOperation) QueuedOperationMetadata(build.buildfarm.v1test.QueuedOperationMetadata) ProfiledQueuedOperationMetadata(build.buildfarm.v1test.ProfiledQueuedOperationMetadata)

Aggregations

Digest (build.bazel.remote.execution.v2.Digest)191 ByteString (com.google.protobuf.ByteString)110 Test (org.junit.Test)99 IOException (java.io.IOException)55 Directory (build.bazel.remote.execution.v2.Directory)42 ImmutableList (com.google.common.collect.ImmutableList)35 Path (java.nio.file.Path)33 Status (io.grpc.Status)30 ExecutionException (java.util.concurrent.ExecutionException)29 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)27 InputStream (java.io.InputStream)25 Instance (build.buildfarm.instance.Instance)24 Action (build.bazel.remote.execution.v2.Action)22 DigestUtil (build.buildfarm.common.DigestUtil)22 OutputStream (java.io.OutputStream)22 Write (build.buildfarm.common.Write)21 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)21 Operation (com.google.longrunning.Operation)21 UUID (java.util.UUID)20 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)19