Search in sources :

Example 1 with FindMissingBlobsRequest

use of build.bazel.remote.execution.v2.FindMissingBlobsRequest in project bazel-buildfarm by bazelbuild.

the class ContentAddressableStorageService method findMissingBlobs.

@Override
public void findMissingBlobs(FindMissingBlobsRequest request, StreamObserver<FindMissingBlobsResponse> responseObserver) {
    FindMissingBlobsResponse.Builder responseBuilder = FindMissingBlobsResponse.newBuilder();
    try {
        for (Digest blobDigest : request.getBlobDigestsList()) {
            if (!simpleBlobStore.containsKey(blobDigest.getHash())) {
                responseBuilder.addMissingBlobDigests(blobDigest);
            }
        }
        responseObserver.onNext(responseBuilder.build());
        responseObserver.onCompleted();
    } catch (IOException e) {
        responseObserver.onError(Status.fromThrowable(e).asException());
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) Digest(build.bazel.remote.execution.v2.Digest) IOException(java.io.IOException)

Example 2 with FindMissingBlobsRequest

use of build.bazel.remote.execution.v2.FindMissingBlobsRequest in project bazel-buildfarm by bazelbuild.

the class BuildFarmServerTest method findMissingBlobs.

@Test
public void findMissingBlobs() {
    DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256);
    ByteString content = ByteString.copyFromUtf8("Hello, World!");
    Iterable<Digest> digests = Collections.singleton(digestUtil.compute(content));
    FindMissingBlobsRequest request = FindMissingBlobsRequest.newBuilder().setInstanceName(INSTANCE_NAME).addAllBlobDigests(digests).build();
    ContentAddressableStorageGrpc.ContentAddressableStorageBlockingStub stub = ContentAddressableStorageGrpc.newBlockingStub(inProcessChannel);
    FindMissingBlobsResponse response = stub.findMissingBlobs(request);
    assertThat(response.getMissingBlobDigestsList()).containsExactlyElementsIn(digests);
}
Also used : FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) Digest(build.bazel.remote.execution.v2.Digest) ByteString(com.google.protobuf.ByteString) ContentAddressableStorageGrpc(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc) DigestUtil(build.buildfarm.common.DigestUtil) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) Test(org.junit.Test)

Example 3 with FindMissingBlobsRequest

use of build.bazel.remote.execution.v2.FindMissingBlobsRequest in project bazel-buildfarm by bazelbuild.

the class StubInstanceTest method findMissingBlobsCallsFindMissingBlobs.

@Test
public void findMissingBlobsCallsFindMissingBlobs() throws ExecutionException, InterruptedException {
    AtomicReference<FindMissingBlobsRequest> reference = new AtomicReference<>();
    serviceRegistry.addService(new ContentAddressableStorageImplBase() {

        @Override
        public void findMissingBlobs(FindMissingBlobsRequest request, StreamObserver<FindMissingBlobsResponse> responseObserver) {
            reference.set(request);
            responseObserver.onNext(FindMissingBlobsResponse.getDefaultInstance());
            responseObserver.onCompleted();
        }
    });
    Instance instance = newStubInstance("findMissingBlobs-test");
    Iterable<Digest> digests = ImmutableList.of(Digest.newBuilder().setHash("present").setSizeBytes(1).build());
    assertThat(instance.findMissingBlobs(digests, RequestMetadata.getDefaultInstance()).get()).isEmpty();
    instance.stop();
}
Also used : FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) Instance(build.buildfarm.instance.Instance) Digest(build.bazel.remote.execution.v2.Digest) ContentAddressableStorageImplBase(build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest) Test(org.junit.Test)

Example 4 with FindMissingBlobsRequest

use of build.bazel.remote.execution.v2.FindMissingBlobsRequest in project bazel-buildfarm by bazelbuild.

the class ContentAddressableStorageService method instanceFindMissingBlobs.

void instanceFindMissingBlobs(Instance instance, FindMissingBlobsRequest request, StreamObserver<FindMissingBlobsResponse> responseObserver) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    FindMissingBlobsResponse.Builder builder = FindMissingBlobsResponse.newBuilder();
    ListenableFuture<FindMissingBlobsResponse.Builder> responseFuture = transform(instance.findMissingBlobs(request.getBlobDigestsList(), TracingMetadataUtils.fromCurrentContext()), builder::addAllMissingBlobDigests, directExecutor());
    addCallback(responseFuture, new FutureCallback<FindMissingBlobsResponse.Builder>() {

        @Override
        public void onSuccess(FindMissingBlobsResponse.Builder builder) {
            try {
                FindMissingBlobsResponse response = builder.build();
                responseObserver.onNext(response);
                responseObserver.onCompleted();
                long elapsedMicros = stopwatch.elapsed(MICROSECONDS);
                missingBlobs.observe(request.getBlobDigestsList().size());
                logger.log(Level.FINE, "FindMissingBlobs(" + instance.getName() + ") for " + request.getBlobDigestsList().size() + " blobs in " + elapsedMicros / 1000.0);
            } catch (Throwable t) {
                onFailure(t);
            }
        }

        @SuppressWarnings("NullableProblems")
        @Override
        public void onFailure(Throwable t) {
            Status status = Status.fromThrowable(t);
            if (status.getCode() != Code.CANCELLED) {
                logger.log(Level.SEVERE, format("findMissingBlobs(%s): %d", request.getInstanceName(), request.getBlobDigestsCount()), t);
                responseObserver.onError(t);
            }
        }
    }, directExecutor());
}
Also used : Status(io.grpc.Status) FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) Stopwatch(com.google.common.base.Stopwatch)

Example 5 with FindMissingBlobsRequest

use of build.bazel.remote.execution.v2.FindMissingBlobsRequest in project bazel-buildfarm by bazelbuild.

the class StubInstance method findMissingBlobs.

@Override
public ListenableFuture<Iterable<Digest>> findMissingBlobs(Iterable<Digest> digests, RequestMetadata requestMetadata) {
    throwIfStopped();
    FindMissingBlobsRequest request = FindMissingBlobsRequest.newBuilder().setInstanceName(getName()).addAllBlobDigests(digests).build();
    if (request.getSerializedSize() > Size.mbToBytes(4)) {
        throw new IllegalStateException(String.format("FINDMISSINGBLOBS IS TOO LARGE: %d digests are required in one request!", request.getBlobDigestsCount()));
    }
    return transform(deadlined(casFutureStub).withInterceptors(attachMetadataInterceptor(requestMetadata)).findMissingBlobs(request), FindMissingBlobsResponse::getMissingBlobDigestsList, directExecutor());
}
Also used : FindMissingBlobsResponse(build.bazel.remote.execution.v2.FindMissingBlobsResponse) FindMissingBlobsRequest(build.bazel.remote.execution.v2.FindMissingBlobsRequest)

Aggregations

FindMissingBlobsResponse (build.bazel.remote.execution.v2.FindMissingBlobsResponse)5 Digest (build.bazel.remote.execution.v2.Digest)3 FindMissingBlobsRequest (build.bazel.remote.execution.v2.FindMissingBlobsRequest)3 Test (org.junit.Test)2 ContentAddressableStorageGrpc (build.bazel.remote.execution.v2.ContentAddressableStorageGrpc)1 ContentAddressableStorageImplBase (build.bazel.remote.execution.v2.ContentAddressableStorageGrpc.ContentAddressableStorageImplBase)1 DigestUtil (build.buildfarm.common.DigestUtil)1 Instance (build.buildfarm.instance.Instance)1 Stopwatch (com.google.common.base.Stopwatch)1 ByteString (com.google.protobuf.ByteString)1 Status (io.grpc.Status)1 IOException (java.io.IOException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1