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));
}
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);
}
}
Aggregations