Search in sources :

Example 6 with CacheRequest

use of alluxio.grpc.CacheRequest in project alluxio by Alluxio.

the class CacheRequestManagerTest method submitAsyncRequestCacheBlockFromRemoteWorker.

@Test
public void submitAsyncRequestCacheBlockFromRemoteWorker() throws Exception {
    String fakeRemoteWorker = mLocalWorkerHostname + "1";
    CacheRequest request = CacheRequest.newBuilder().setBlockId(BLOCK_ID).setLength(CHUNK_SIZE).setOpenUfsBlockOptions(mOpenUfsBlockOptions).setSourceHost(fakeRemoteWorker).setSourcePort(PORT).setAsync(true).build();
    setupMockRemoteReader(fakeRemoteWorker, PORT, BLOCK_ID, CHUNK_SIZE, mOpenUfsBlockOptions);
    mCacheRequestManager.submitRequest(request);
    CommonUtils.waitFor("wait for async cache", () -> mBlockWorker.hasBlockMeta(BLOCK_ID));
}
Also used : CacheRequest(alluxio.grpc.CacheRequest) Test(org.junit.Test)

Example 7 with CacheRequest

use of alluxio.grpc.CacheRequest in project alluxio by Alluxio.

the class JobUtils method loadThroughCacheRequest.

private static void loadThroughCacheRequest(URIStatus status, FileSystemContext context, long blockId, AlluxioConfiguration conf, WorkerNetAddress localNetAddress) throws IOException {
    AlluxioBlockStore blockStore = AlluxioBlockStore.create(context);
    OpenFilePOptions openOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE).build();
    InStreamOptions inOptions = new InStreamOptions(status, openOptions, conf);
    BlockLocationPolicy policy = BlockLocationPolicy.Factory.create(LocalFirstPolicy.class.getCanonicalName(), conf);
    inOptions.setUfsReadLocationPolicy(policy);
    Protocol.OpenUfsBlockOptions openUfsBlockOptions = inOptions.getOpenUfsBlockOptions(blockId);
    BlockInfo info = Preconditions.checkNotNull(status.getBlockInfo(blockId));
    long blockLength = info.getLength();
    Pair<WorkerNetAddress, BlockInStream.BlockInStreamSource> dataSourceAndType = blockStore.getDataSourceAndType(status.getBlockInfo(blockId), status, policy, ImmutableMap.of());
    WorkerNetAddress dataSource = dataSourceAndType.getFirst();
    String host = dataSource.getHost();
    // to establish the connection.
    if (!dataSource.getContainerHost().equals("")) {
        host = dataSource.getContainerHost();
    }
    CacheRequest request = CacheRequest.newBuilder().setBlockId(blockId).setLength(blockLength).setOpenUfsBlockOptions(openUfsBlockOptions).setSourceHost(host).setSourcePort(dataSource.getDataPort()).build();
    try (CloseableResource<BlockWorkerClient> blockWorker = context.acquireBlockWorkerClient(localNetAddress)) {
        blockWorker.get().cache(request);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : IOException(java.io.IOException) LocalFirstPolicy(alluxio.client.block.policy.LocalFirstPolicy) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) NotFoundException(alluxio.exception.status.NotFoundException) InStreamOptions(alluxio.client.file.options.InStreamOptions) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) CacheRequest(alluxio.grpc.CacheRequest) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) Protocol(alluxio.proto.dataserver.Protocol)

Aggregations

CacheRequest (alluxio.grpc.CacheRequest)7 Test (org.junit.Test)4 BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)3 BlockInfo (alluxio.wire.BlockInfo)3 IOException (java.io.IOException)3 AlluxioException (alluxio.exception.AlluxioException)2 WorkerNetAddress (alluxio.wire.WorkerNetAddress)2 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)1 BlockLocationPolicy (alluxio.client.block.policy.BlockLocationPolicy)1 LocalFirstPolicy (alluxio.client.block.policy.LocalFirstPolicy)1 InStreamOptions (alluxio.client.file.options.InStreamOptions)1 InvalidArgumentException (alluxio.exception.status.InvalidArgumentException)1 NotFoundException (alluxio.exception.status.NotFoundException)1 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)1 Protocol (alluxio.proto.dataserver.Protocol)1 FileBlockInfo (alluxio.wire.FileBlockInfo)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1