use of alluxio.client.file.options.InStreamOptions 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