Search in sources :

Example 1 with CasUploadTreeMetadataReply

use of com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataReply in project bazel by bazelbuild.

the class GrpcActionCache method uploadTree.

/**
   * Upload enough of the tree metadata and data into remote cache so that the entire tree can be
   * reassembled remotely using the root digest.
   */
@Override
public void uploadTree(TreeNodeRepository repository, Path execRoot, TreeNode root) throws IOException, InterruptedException {
    repository.computeMerkleDigests(root);
    // TODO(olaola): avoid querying all the digests, only ask for novel subtrees.
    ImmutableSet<ContentDigest> missingDigests = getMissingDigests(repository.getAllDigests(root));
    // Only upload data that was missing from the cache.
    ArrayList<ActionInput> actionInputs = new ArrayList<>();
    ArrayList<FileNode> treeNodes = new ArrayList<>();
    repository.getDataFromDigests(missingDigests, actionInputs, treeNodes);
    if (!treeNodes.isEmpty()) {
        CasUploadTreeMetadataRequest.Builder metaRequest = CasUploadTreeMetadataRequest.newBuilder().addAllTreeNode(treeNodes);
        CasUploadTreeMetadataReply reply = getBlockingStub().uploadTreeMetadata(metaRequest.build());
        if (!reply.getStatus().getSucceeded()) {
            throw new RuntimeException(reply.getStatus().getErrorDetail());
        }
    }
    if (!actionInputs.isEmpty()) {
        ArrayList<Path> paths = new ArrayList<>();
        for (ActionInput actionInput : actionInputs) {
            paths.add(execRoot.getRelative(actionInput.getExecPathString()));
        }
        uploadChunks(paths.size(), new BlobChunkFileIterator(missingDigests, paths.iterator()));
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ActionInput(com.google.devtools.build.lib.actions.ActionInput) ArrayList(java.util.ArrayList) CasUploadTreeMetadataReply(com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataReply) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest) CasUploadTreeMetadataRequest(com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) FileNode(com.google.devtools.build.lib.remote.RemoteProtocol.FileNode)

Aggregations

ActionInput (com.google.devtools.build.lib.actions.ActionInput)1 CasUploadTreeMetadataReply (com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataReply)1 CasUploadTreeMetadataRequest (com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataRequest)1 ContentDigest (com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest)1 FileNode (com.google.devtools.build.lib.remote.RemoteProtocol.FileNode)1 Path (com.google.devtools.build.lib.vfs.Path)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ArrayList (java.util.ArrayList)1