Search in sources :

Example 11 with ContentDigest

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;
}
Also used : FileNode(com.google.devtools.build.lib.remote.RemoteProtocol.FileNode) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)

Example 12 with ContentDigest

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());
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)

Example 13 with ContentDigest

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;
}
Also used : ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)

Example 14 with ContentDigest

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;
}
Also used : ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)

Example 15 with ContentDigest

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);
}
Also used : CasDownloadReply(com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadReply) HashMap(java.util.HashMap) FileMetadata(com.google.devtools.build.lib.remote.RemoteProtocol.FileMetadata) CasDownloadBlobRequest(com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadBlobRequest) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest) Pair(com.google.devtools.build.lib.util.Pair)

Aggregations

ContentDigest (com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)21 Test (org.junit.Test)8 Path (com.google.devtools.build.lib.vfs.Path)7 ByteString (com.google.protobuf.ByteString)5 ArrayList (java.util.ArrayList)5 CasDownloadReply (com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadReply)4 CasDownloadBlobRequest (com.google.devtools.build.lib.remote.RemoteProtocol.CasDownloadBlobRequest)3 FileMetadata (com.google.devtools.build.lib.remote.RemoteProtocol.FileMetadata)3 FileNode (com.google.devtools.build.lib.remote.RemoteProtocol.FileNode)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 HashMap (java.util.HashMap)3 ActionInput (com.google.devtools.build.lib.actions.ActionInput)2 ActionResult (com.google.devtools.build.lib.remote.RemoteProtocol.ActionResult)2 BlobChunk (com.google.devtools.build.lib.remote.RemoteProtocol.BlobChunk)2 Pair (com.google.devtools.build.lib.util.Pair)2 IOException (java.io.IOException)2 Artifact (com.google.devtools.build.lib.actions.Artifact)1 CasUploadTreeMetadataReply (com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataReply)1 CasUploadTreeMetadataRequest (com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataRequest)1 Output (com.google.devtools.build.lib.remote.RemoteProtocol.Output)1