Search in sources :

Example 1 with UniformDelegateServerCallStreamObserver

use of build.buildfarm.common.grpc.UniformDelegateServerCallStreamObserver in project bazel-buildfarm by bazelbuild.

the class ByteStreamService method onErrorLogReadObserver.

ServerCallStreamObserver<ReadResponse> onErrorLogReadObserver(String name, long offset, ServerCallStreamObserver<ReadResponse> delegate) {
    return new UniformDelegateServerCallStreamObserver<ReadResponse>(delegate) {

        long responseCount = 0;

        long responseBytes = 0;

        @Override
        public void onNext(ReadResponse response) {
            delegate.onNext(response);
            responseCount++;
            responseBytes += response.getData().size();
        }

        @Override
        public void onError(Throwable t) {
            Status status = Status.fromThrowable(t);
            if (status.getCode() != Code.NOT_FOUND) {
                java.util.logging.Level level = Level.SEVERE;
                if (responseCount > 0 && status.getCode() == Code.DEADLINE_EXCEEDED || status.getCode() == Code.CANCELLED) {
                    level = Level.WARNING;
                }
                String message = format("error reading %s at offset %d", name, offset);
                if (responseCount > 0) {
                    message += format(" after %d responses and %d bytes of content", responseCount, responseBytes);
                }
                logger.log(level, message, t);
            }
            delegate.onError(t);
        }

        @Override
        public void onCompleted() {
            delegate.onCompleted();
        }
    };
}
Also used : Status(io.grpc.Status) ReadResponse(com.google.bytestream.ByteStreamProto.ReadResponse) UniformDelegateServerCallStreamObserver(build.buildfarm.common.grpc.UniformDelegateServerCallStreamObserver) ByteString(com.google.protobuf.ByteString) Level(java.util.logging.Level)

Example 2 with UniformDelegateServerCallStreamObserver

use of build.buildfarm.common.grpc.UniformDelegateServerCallStreamObserver in project bazel-buildfarm by bazelbuild.

the class ShardInstance method getBlob.

@Override
public void getBlob(Digest blobDigest, long offset, long count, ServerCallStreamObserver<ByteString> blobObserver, RequestMetadata requestMetadata) {
    List<String> workersList;
    Set<String> workerSet;
    Set<String> locationSet;
    try {
        workerSet = backplane.getWorkers();
        locationSet = backplane.getBlobLocationSet(blobDigest);
        synchronized (workerSet) {
            workersList = new ArrayList<>(Sets.intersection(locationSet, workerSet));
        }
    } catch (IOException e) {
        blobObserver.onError(e);
        return;
    }
    boolean emptyWorkerList = workersList.isEmpty();
    final ListenableFuture<List<String>> populatedWorkerListFuture;
    if (emptyWorkerList) {
        logger.log(Level.FINE, format("worker list was initially empty for %s, attempting to correct", DigestUtil.toString(blobDigest)));
        populatedWorkerListFuture = transform(correctMissingBlob(backplane, workerSet, locationSet, this::workerStub, blobDigest, directExecutor(), RequestMetadata.getDefaultInstance()), (foundOnWorkers) -> {
            logger.log(Level.FINE, format("worker list was corrected for %s to be %s", DigestUtil.toString(blobDigest), foundOnWorkers.toString()));
            Iterables.addAll(workersList, foundOnWorkers);
            return workersList;
        }, directExecutor());
    } else {
        populatedWorkerListFuture = immediateFuture(workersList);
    }
    Context ctx = Context.current();
    ServerCallStreamObserver<ByteString> chunkObserver = new UniformDelegateServerCallStreamObserver<ByteString>(blobObserver) {

        boolean triedCheck = emptyWorkerList;

        @Override
        public void onNext(ByteString nextChunk) {
            blobObserver.onNext(nextChunk);
        }

        @Override
        public void onError(Throwable t) {
            Status status = Status.fromThrowable(t);
            if (status.getCode() == Code.NOT_FOUND && !triedCheck) {
                triedCheck = true;
                workersList.clear();
                final ListenableFuture<List<String>> workersListFuture;
                logger.log(Level.FINE, format("worker list was depleted for %s, attempting to correct", DigestUtil.toString(blobDigest)));
                workersListFuture = transform(correctMissingBlob(backplane, workerSet, locationSet, ShardInstance.this::workerStub, blobDigest, directExecutor(), RequestMetadata.getDefaultInstance()), (foundOnWorkers) -> {
                    logger.log(Level.FINE, format("worker list was corrected after depletion for %s to be %s", DigestUtil.toString(blobDigest), foundOnWorkers.toString()));
                    Iterables.addAll(workersList, foundOnWorkers);
                    return workersList;
                }, directExecutor());
                final ServerCallStreamObserver<ByteString> checkedChunkObserver = this;
                addCallback(workersListFuture, new WorkersCallback(rand) {

                    @Override
                    public void onQueue(Deque<String> workers) {
                        ctx.run(() -> fetchBlobFromWorker(blobDigest, workers, offset, count, checkedChunkObserver, requestMetadata));
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        blobObserver.onError(t);
                    }
                }, directExecutor());
            } else {
                blobObserver.onError(t);
            }
        }

        @Override
        public void onCompleted() {
            blobObserver.onCompleted();
        }
    };
    addCallback(populatedWorkerListFuture, new WorkersCallback(rand) {

        @Override
        public void onQueue(Deque<String> workers) {
            ctx.run(() -> fetchBlobFromWorker(blobDigest, workers, offset, count, chunkObserver, requestMetadata));
        }

        @Override
        public void onFailure(Throwable t) {
            blobObserver.onError(t);
        }
    }, directExecutor());
}
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) Context(io.grpc.Context) Status(io.grpc.Status) Actions.asExecutionStatus(build.buildfarm.common.Actions.asExecutionStatus) QueueStatus(build.buildfarm.v1test.QueueStatus) BackplaneStatus(build.buildfarm.v1test.BackplaneStatus) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) UniformDelegateServerCallStreamObserver(build.buildfarm.common.grpc.UniformDelegateServerCallStreamObserver) Futures.allAsList(com.google.common.util.concurrent.Futures.allAsList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

UniformDelegateServerCallStreamObserver (build.buildfarm.common.grpc.UniformDelegateServerCallStreamObserver)2 ByteString (com.google.protobuf.ByteString)2 Status (io.grpc.Status)2 Level (java.util.logging.Level)2 Action (build.bazel.remote.execution.v2.Action)1 ActionResult (build.bazel.remote.execution.v2.ActionResult)1 Command (build.bazel.remote.execution.v2.Command)1 Digest (build.bazel.remote.execution.v2.Digest)1 Directory (build.bazel.remote.execution.v2.Directory)1 DirectoryNode (build.bazel.remote.execution.v2.DirectoryNode)1 ExecuteOperationMetadata (build.bazel.remote.execution.v2.ExecuteOperationMetadata)1 ExecuteResponse (build.bazel.remote.execution.v2.ExecuteResponse)1 ExecutionPolicy (build.bazel.remote.execution.v2.ExecutionPolicy)1 ExecutionStage (build.bazel.remote.execution.v2.ExecutionStage)1 Platform (build.bazel.remote.execution.v2.Platform)1 Property (build.bazel.remote.execution.v2.Platform.Property)1 RequestMetadata (build.bazel.remote.execution.v2.RequestMetadata)1 ResultsCachePolicy (build.bazel.remote.execution.v2.ResultsCachePolicy)1 Backplane (build.buildfarm.backplane.Backplane)1 Actions.asExecutionStatus (build.buildfarm.common.Actions.asExecutionStatus)1