Search in sources :

Example 41 with Digest

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

the class GrpcCAS method findMissingBlobs.

@Override
public Iterable<Digest> findMissingBlobs(Iterable<Digest> digests) {
    digests = StreamSupport.stream(digests.spliterator(), false).filter(digest -> digest.getSizeBytes() != 0).collect(Collectors.toList());
    if (Iterables.isEmpty(digests)) {
        return ImmutableList.of();
    }
    List<Digest> missingDigests = casBlockingStub.get().findMissingBlobs(FindMissingBlobsRequest.newBuilder().setInstanceName(instanceName).addAllBlobDigests(digests).build()).getMissingBlobDigestsList();
    for (Digest missingDigest : missingDigests) {
        expire(missingDigest);
    }
    return missingDigests;
}
Also used : Digest(build.bazel.remote.execution.v2.Digest)

Example 42 with Digest

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

the class MemoryCAS method expireEntry.

@GuardedBy("this")
private void expireEntry(Entry e) {
    Digest digest = DigestUtil.buildDigest(e.key, e.value.size());
    logger.log(Level.INFO, "MemoryLRUCAS: expiring " + DigestUtil.toString(digest));
    if (delegate != null) {
        try {
            Write write = delegate.getWrite(digest, UUID.randomUUID(), RequestMetadata.getDefaultInstance());
            try (OutputStream out = write.getOutput(1, MINUTES, () -> {
            })) {
                e.value.getData().writeTo(out);
            }
        } catch (IOException ioEx) {
            logger.log(Level.SEVERE, String.format("error delegating %s", DigestUtil.toString(digest)), ioEx);
        }
    }
    storage.remove(e.key);
    e.expire();
    sizeInBytes -= digest.getSizeBytes();
}
Also used : Write(build.buildfarm.common.Write) Digest(build.bazel.remote.execution.v2.Digest) OutputStream(java.io.OutputStream) IOException(java.io.IOException) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 43 with Digest

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

the class MemoryCAS method findMissingBlobs.

@Override
public Iterable<Digest> findMissingBlobs(Iterable<Digest> digests) throws InterruptedException {
    ImmutableList.Builder<Digest> builder = ImmutableList.builder();
    synchronized (this) {
        // incur access use of the digest
        for (Digest digest : digests) {
            if (digest.getSizeBytes() != 0 && !contains(digest, Digest.newBuilder())) {
                builder.add(digest);
            }
        }
    }
    ImmutableList<Digest> missing = builder.build();
    if (delegate != null && !missing.isEmpty()) {
        return delegate.findMissingBlobs(missing);
    }
    return missing;
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) ImmutableList(com.google.common.collect.ImmutableList)

Example 44 with Digest

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

the class SqliteFileDirectoriesIndex method removeEntryDirectories.

@GuardedBy("this")
private Set<Digest> removeEntryDirectories(String entry) {
    open();
    String selectSql = "SELECT directory FROM entries WHERE path = ?";
    ImmutableSet.Builder<Digest> directoriesBuilder = ImmutableSet.builder();
    try (PreparedStatement selectStatement = conn.prepareStatement(selectSql)) {
        selectStatement.setString(1, entry);
        try (ResultSet rs = selectStatement.executeQuery()) {
            while (rs.next()) {
                directoriesBuilder.add(DigestUtil.parseDigest(rs.getString("directory")));
            }
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    // all directories featuring this entry are now invalid
    ImmutableSet<Digest> directories = directoriesBuilder.build();
    String deleteSql = "DELETE FROM entries where directory = ?";
    try (PreparedStatement deleteStatement = conn.prepareStatement(deleteSql)) {
        conn.setAutoCommit(false);
        for (Digest directory : directories) {
            deleteStatement.setString(1, DigestUtil.toString(directory));
            deleteStatement.addBatch();
        }
        deleteStatement.executeBatch();
        conn.commit();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    return directories;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Digest(build.bazel.remote.execution.v2.Digest) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 45 with Digest

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

the class TreeIterator method next.

@Override
public DirectoryEntry next() throws NoSuchElementException {
    Iterator<Digest> iter = pointers.peek();
    if (!iter.hasNext()) {
        throw new NoSuchElementException();
    }
    /* we can have null directories in our list
     * if members of the tree have been removed from
     * the cas.  we return this to retain the information
     * (and simplify the interface) that they have been
     * removed. */
    Digest digest = iter.next();
    Directory directory = getDirectory(digest);
    if (directory != null) {
        /* the path to a new iter set is the path to its parent */
        parentPath.addLast(digest);
        path = parentPath.clone();
        pointers.push(Iterators.transform(directory.getDirectoriesList().iterator(), DirectoryNode::getDigest));
    }
    advanceIterator();
    return new DirectoryEntry(digest, directory);
}
Also used : Digest(build.bazel.remote.execution.v2.Digest) NoSuchElementException(java.util.NoSuchElementException) Directory(build.bazel.remote.execution.v2.Directory)

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