Search in sources :

Example 16 with Digest

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

the class RedissonCasWorkerMap method removeAll.

/**
 * @brief Remove worker value from all blob keys.
 * @details If the blob is already missing, or the worker doesn't exist, this will be no effect on
 *     the key.
 * @param client Client used for interacting with redis when not using cacheMap.
 * @param blobDigests The blob digests to remove the worker from.
 * @param workerName The worker name to remove.
 */
@Override
public void removeAll(RedisClient client, Iterable<Digest> blobDigests, String workerName) {
    for (Digest blobDigest : blobDigests) {
        String key = cacheMapCasKey(blobDigest);
        cacheMap.remove(key, workerName);
    }
}
Also used : Digest(build.bazel.remote.execution.v2.Digest)

Example 17 with Digest

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

the class RedissonCasWorkerMap method getMap.

/**
 * @brief Get all of the key values as a map from the digests given.
 * @details If there are no workers for the digest, the key is left out of the returned map.
 * @param client Client used for interacting with redis when not using cacheMap.
 * @param blobDigests The blob digests to get the key/values for.
 * @return The key/value map for digests to workers.
 * @note Suggested return identifier: casWorkerMap.
 */
@Override
public Map<Digest, Set<String>> getMap(RedisClient client, Iterable<Digest> blobDigests) {
    ImmutableMap.Builder<Digest, Set<String>> blobDigestsWorkers = new ImmutableMap.Builder<>();
    for (Digest blobDigest : blobDigests) {
        String key = cacheMapCasKey(blobDigest);
        Set<String> workers = cacheMap.get(key).readAll();
        if (workers.isEmpty()) {
            continue;
        }
        blobDigestsWorkers.put(blobDigest, workers);
    }
    return blobDigestsWorkers.build();
}
Also used : Set(java.util.Set) Digest(build.bazel.remote.execution.v2.Digest) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 18 with Digest

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

the class RedissonCasWorkerMap method addAll.

/**
 * @brief Update multiple blob entries for a worker.
 * @details This may add a new key if the blob did not previously exist, or it will adjust the
 *     worker values based on the worker name. The expiration time is always refreshed.
 * @param client Client used for interacting with redis when not using cacheMap.
 * @param blobDigests The blob digests to adjust worker information from.
 * @param workerName The worker to add for looking up the blobs.
 */
@Override
public void addAll(RedisClient client, Iterable<Digest> blobDigests, String workerName) {
    for (Digest blobDigest : blobDigests) {
        String key = cacheMapCasKey(blobDigest);
        cacheMap.put(key, workerName);
        cacheMap.expireKey(key, keyExpiration_s, TimeUnit.SECONDS);
    }
}
Also used : Digest(build.bazel.remote.execution.v2.Digest)

Example 19 with Digest

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

the class RemoteInputStreamFactory method newInput.

@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
public InputStream newInput(Digest blobDigest, long offset, long deadlineAfter, TimeUnit deadlineAfterUnits, RequestMetadata requestMetadata) throws IOException, InterruptedException {
    Set<String> remoteWorkers;
    Set<String> locationSet;
    try {
        Set<String> workers = backplane.getWorkers();
        if (publicName == null) {
            remoteWorkers = workers;
        } else {
            synchronized (workers) {
                remoteWorkers = Sets.difference(workers, ImmutableSet.of(publicName)).immutableCopy();
            }
        }
        locationSet = Sets.newHashSet(Sets.intersection(backplane.getBlobLocationSet(blobDigest), workers));
    } catch (IOException e) {
        throw Status.fromThrowable(e).asRuntimeException();
    }
    if (publicName != null && locationSet.remove(publicName)) {
        backplane.removeBlobLocation(blobDigest, publicName);
    }
    List<String> workersList = new ArrayList<>(locationSet);
    boolean emptyWorkerList = workersList.isEmpty();
    final ListenableFuture<List<String>> populatedWorkerListFuture;
    if (emptyWorkerList) {
        populatedWorkerListFuture = transform(correctMissingBlob(backplane, remoteWorkers, locationSet, this::workerStub, blobDigest, newDirectExecutorService(), requestMetadata), (foundOnWorkers) -> {
            Iterables.addAll(workersList, foundOnWorkers);
            return workersList;
        }, directExecutor());
    } else {
        populatedWorkerListFuture = immediateFuture(workersList);
    }
    SettableFuture<InputStream> inputStreamFuture = SettableFuture.create();
    addCallback(populatedWorkerListFuture, new WorkersCallback(rand) {

        boolean triedCheck = emptyWorkerList;

        @Override
        public void onQueue(Deque<String> workers) {
            Set<String> locationSet = Sets.newHashSet(workers);
            boolean complete = false;
            while (!complete && !workers.isEmpty()) {
                try {
                    inputStreamFuture.set(fetchBlobFromRemoteWorker(blobDigest, workers, offset, deadlineAfter, deadlineAfterUnits, requestMetadata));
                    complete = true;
                } catch (IOException e) {
                    if (workers.isEmpty()) {
                        if (triedCheck) {
                            onFailure(e);
                            return;
                        }
                        triedCheck = true;
                        workersList.clear();
                        ListenableFuture<List<String>> checkedWorkerListFuture = transform(correctMissingBlob(backplane, remoteWorkers, locationSet, RemoteInputStreamFactory.this::workerStub, blobDigest, newDirectExecutorService(), requestMetadata), (foundOnWorkers) -> {
                            Iterables.addAll(workersList, foundOnWorkers);
                            return workersList;
                        }, directExecutor());
                        addCallback(checkedWorkerListFuture, this, directExecutor());
                        complete = true;
                    }
                } catch (InterruptedException e) {
                    complete = true;
                    onFailure(e);
                }
            }
        }

        @SuppressWarnings("NullableProblems")
        @Override
        public void onFailure(Throwable t) {
            Status status = Status.fromThrowable(t);
            if (status.getCode() == Code.NOT_FOUND) {
                inputStreamFuture.setException(new NoSuchFileException(DigestUtil.toString(blobDigest)));
            } else {
                inputStreamFuture.setException(t);
            }
        }
    }, directExecutor());
    try {
        return inputStreamFuture.get();
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        Throwables.throwIfUnchecked(cause);
        Throwables.throwIfInstanceOf(cause, IOException.class);
        Throwables.throwIfInstanceOf(cause, InterruptedException.class);
        throw new UncheckedExecutionException(cause);
    }
}
Also used : Iterables(com.google.common.collect.Iterables) NoSuchFileException(java.nio.file.NoSuchFileException) LoadingCache(com.google.common.cache.LoadingCache) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) MoreExecutors.newDirectExecutorService(com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService) RequestMetadata(build.bazel.remote.execution.v2.RequestMetadata) Random(java.util.Random) Util.correctMissingBlob(build.buildfarm.instance.shard.Util.correctMissingBlob) InputStreamFactory(build.buildfarm.common.InputStreamFactory) SettableFuture(com.google.common.util.concurrent.SettableFuture) Deque(java.util.Deque) DigestUtil(build.buildfarm.common.DigestUtil) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) SHARD_IS_RETRIABLE(build.buildfarm.instance.shard.Util.SHARD_IS_RETRIABLE) Code(io.grpc.Status.Code) Futures.addCallback(com.google.common.util.concurrent.Futures.addCallback) Digest(build.bazel.remote.execution.v2.Digest) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Status(io.grpc.Status) Nullable(javax.annotation.Nullable) WorkersCallback(build.buildfarm.instance.shard.ShardInstance.WorkersCallback) Backplane(build.buildfarm.backplane.Backplane) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) ImmutableSet(com.google.common.collect.ImmutableSet) Throwables(com.google.common.base.Throwables) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) Instance(build.buildfarm.instance.Instance) Sets(com.google.common.collect.Sets) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Futures.transform(com.google.common.util.concurrent.Futures.transform) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InputStream(java.io.InputStream) Status(io.grpc.Status) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) WorkersCallback(build.buildfarm.instance.shard.ShardInstance.WorkersCallback) ArrayList(java.util.ArrayList) List(java.util.List) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 20 with Digest

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

the class DelegateCASMap method remove.

public V remove(K key) {
    Digest valueDigest = digestMap.remove(key);
    if (valueDigest == null) {
        if (emptyCache.getIfPresent(key) == null) {
            return null;
        }
        emptyCache.invalidate(key);
        valueDigest = digestUtil.empty();
    }
    return expectValueType(valueDigest);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest)

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