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;
}
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();
}
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;
}
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;
}
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);
}
Aggregations