use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.
the class TreeNodeRepository method getOrComputeFileNode.
private synchronized FileNode getOrComputeFileNode(TreeNode node) throws IOException {
// Assumes all child digests have already been computed!
FileNode fileNode = fileNodeCache.get(node);
if (fileNode == null) {
FileNode.Builder b = FileNode.newBuilder();
if (node.isLeaf()) {
ContentDigest fileDigest = fileContentsDigestCache.get(node.getActionInput());
Preconditions.checkState(fileDigest != null);
b.getFileMetadataBuilder().setDigest(fileDigest).setExecutable(execRoot.getRelative(node.getActionInput().getExecPathString()).isExecutable());
} else {
for (TreeNode.ChildEntry entry : node.getChildEntries()) {
ContentDigest childDigest = treeNodeDigestCache.get(entry.getChild());
Preconditions.checkState(childDigest != null);
b.addChildBuilder().setPath(entry.getSegment()).setDigest(childDigest);
}
}
fileNode = b.build();
fileNodeCache.put(node, fileNode);
ContentDigest digest = ContentDigests.computeDigest(fileNode);
treeNodeDigestCache.put(node, digest);
digestTreeNodeCache.put(digest, node);
}
return fileNode;
}
use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.
the class ConcurrentMapActionCache method uploadAllResults.
@Override
public void uploadAllResults(Path execRoot, Collection<Path> files, ActionResult.Builder result) throws IOException, InterruptedException {
for (Path file : files) {
if (file.isDirectory()) {
// TreeNodeRepository to call uploadTree.
throw new UnsupportedOperationException("Storing a directory is not yet supported.");
}
// First put the file content to cache.
ContentDigest digest = uploadFileContents(file);
// Add to protobuf.
result.addOutputBuilder().setPath(file.relativeTo(execRoot).getPathString()).getFileMetadataBuilder().setDigest(digest).setExecutable(file.isExecutable());
}
}
use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.
the class ConcurrentMapActionCache method uploadBlob.
@Override
public ContentDigest uploadBlob(byte[] blob) throws InterruptedException {
int blobSizeKBytes = blob.length / 1024;
Preconditions.checkArgument(blobSizeKBytes < MAX_MEMORY_KBYTES);
ContentDigest digest = ContentDigests.computeDigest(blob);
uploadMemoryAvailable.acquire(blobSizeKBytes);
try {
cache.put(ContentDigests.toHexString(digest), blob);
} finally {
uploadMemoryAvailable.release(blobSizeKBytes);
}
return digest;
}
use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.
the class GrpcActionCache method uploadFileContents.
/**
* Put the file contents cache if it is not already in it. No-op if the file is already stored in
* cache. The given path must be a full absolute path. Note: this is horribly inefficient, need to
* patch through an overload that uses an ActionInputFile cache to compute the digests!
*
* @return The key for fetching the file contents blob from cache.
*/
@Override
public ContentDigest uploadFileContents(Path file) throws IOException, InterruptedException {
ContentDigest digest = ContentDigests.computeDigest(file);
ImmutableSet<ContentDigest> missing = getMissingDigests(ImmutableList.of(digest));
if (!missing.isEmpty()) {
uploadChunks(1, new BlobChunkFileIterator(file));
}
return digest;
}
use of com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest in project bazel by bazelbuild.
the class GrpcActionCache method downloadFileContents.
/**
* Download a blob keyed by the given digest and write it to the specified path. Set the
* executable parameter to the specified value.
*/
@Override
public void downloadFileContents(ContentDigest digest, Path dest, boolean executable) throws IOException, CacheNotFoundException {
// Send all the file requests in a single synchronous batch.
// TODO(olaola): profile to maybe replace with separate concurrent requests.
CasDownloadBlobRequest.Builder request = CasDownloadBlobRequest.newBuilder().addDigest(digest);
Iterator<CasDownloadReply> replies = getBlockingStub().downloadBlob(request.build());
FileMetadata fileMetadata = FileMetadata.newBuilder().setDigest(digest).setExecutable(executable).build();
Map<ContentDigest, Pair<Path, FileMetadata>> metadataMap = new HashMap<>();
metadataMap.put(digest, Pair.of(dest, fileMetadata));
createFileFromStream(metadataMap, replies);
}
Aggregations