Search in sources :

Example 1 with StoreLocalChangesRequest

use of com.facebook.buck.distributed.thrift.StoreLocalChangesRequest in project buck by facebook.

the class DistBuildService method uploadMissingFilesFromList.

private ListenableFuture<Void> uploadMissingFilesFromList(final List<FileInfo> fileList, ListeningExecutorService executorService) {
    return executorService.submit(() -> {
        Map<String, FileInfo> sha1ToFileInfo = new HashMap<>();
        for (FileInfo file : fileList) {
            sha1ToFileInfo.put(file.getContentHash(), file);
        }
        List<String> contentHashes = ImmutableList.copyOf(sha1ToFileInfo.keySet());
        CASContainsRequest containsReq = new CASContainsRequest();
        containsReq.setContentSha1s(contentHashes);
        FrontendRequest request = new FrontendRequest();
        request.setType(FrontendRequestType.CAS_CONTAINS);
        request.setCasContainsRequest(containsReq);
        FrontendResponse response = makeRequestChecked(request);
        Preconditions.checkState(response.getCasContainsResponse().exists.size() == contentHashes.size());
        List<Boolean> isPresent = response.getCasContainsResponse().exists;
        List<FileInfo> filesToBeUploaded = new LinkedList<>();
        for (int i = 0; i < isPresent.size(); ++i) {
            if (isPresent.get(i)) {
                continue;
            }
            filesToBeUploaded.add(sha1ToFileInfo.get(contentHashes.get(i)));
        }
        LOG.info("%d out of %d files already exist in the cache. Uploading %d files..", sha1ToFileInfo.size() - filesToBeUploaded.size(), sha1ToFileInfo.size(), filesToBeUploaded.size());
        request = new FrontendRequest();
        StoreLocalChangesRequest storeReq = new StoreLocalChangesRequest();
        storeReq.setFiles(filesToBeUploaded);
        request.setType(FrontendRequestType.STORE_LOCAL_CHANGES);
        request.setStoreLocalChangesRequest(storeReq);
        makeRequestChecked(request);
        // No response expected.
        return null;
    });
}
Also used : CASContainsRequest(com.facebook.buck.distributed.thrift.CASContainsRequest) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) FileInfo(com.facebook.buck.distributed.thrift.FileInfo) StoreLocalChangesRequest(com.facebook.buck.distributed.thrift.StoreLocalChangesRequest) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest)

Aggregations

CASContainsRequest (com.facebook.buck.distributed.thrift.CASContainsRequest)1 FileInfo (com.facebook.buck.distributed.thrift.FileInfo)1 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)1 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)1 StoreLocalChangesRequest (com.facebook.buck.distributed.thrift.StoreLocalChangesRequest)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1