use of alluxio.worker.block.io.LocalFileBlockReader in project alluxio by Alluxio.
the class UnderFileSystemBlockInStream method create.
/**
* Creates an instance of {@link UnderFileSystemBlockInStream}.
* This method keeps polling the block worker until the block is cached to Alluxio or
* it successfully acquires a UFS read token with a timeout.
* (1) If the block is cached to Alluxio after polling, it returns {@link BufferedBlockInStream}
* to read the block from Alluxio storage.
* (2) If a UFS read token is acquired after polling, it returns
* {@link UnderFileSystemBlockInStream} to read the block from an Alluxio worker that reads
* the block from UFS.
* (3) If the polling times out, an {@link IOException} with cause
* {@link alluxio.exception.UfsBlockAccessTokenUnavailableException} is thrown.
*
* @param context the file system context
* @param ufsPath the UFS path
* @param blockId the block ID
* @param blockSize the block size
* @param blockStart the start position of the block in the UFS file
* @param workerNetAddress the worker network address
* @param options the in stream options
* @return the {@link UnderFileSystemBlockInStream} instance or the {@link BufferedBlockOutStream}
* that reads from Alluxio directly
* @throws IOException if it fails to create {@link UnderFileSystemBlockInStream}
*/
public static BufferedBlockInStream create(FileSystemContext context, String ufsPath, long blockId, long blockSize, long blockStart, WorkerNetAddress workerNetAddress, InStreamOptions options) throws IOException {
Closer closer = Closer.create();
try {
BlockWorkerClient blockWorkerClient = closer.register(context.createBlockWorkerClient(workerNetAddress));
LockBlockOptions lockBlockOptions = LockBlockOptions.defaults().setUfsPath(ufsPath).setOffset(blockStart).setBlockSize(blockSize).setMaxUfsReadConcurrency(options.getMaxUfsReadConcurrency());
LockBlockResult result = closer.register(blockWorkerClient.lockUfsBlock(blockId, lockBlockOptions)).getResult();
if (result.getLockBlockStatus().blockInAlluxio()) {
boolean local = blockWorkerClient.getDataServerAddress().getHostName().equals(NetworkAddressUtils.getLocalHostName());
if (local) {
LocalFileBlockReader reader = closer.register(new LocalFileBlockReader(result.getBlockPath()));
return LocalBlockInStream.createWithLockedBlock(blockWorkerClient, blockId, blockSize, reader, closer, options);
} else {
return RemoteBlockInStream.createWithLockedBlock(context, blockWorkerClient, blockId, blockSize, result.getLockId(), closer, options);
}
}
Preconditions.checkState(result.getLockBlockStatus().ufsTokenAcquired());
return new UnderFileSystemBlockInStream(context, blockId, blockSize, blockWorkerClient, closer, options);
} catch (AlluxioException | IOException e) {
CommonUtils.closeQuitely(closer);
throw CommonUtils.castToIOException(e);
}
}
use of alluxio.worker.block.io.LocalFileBlockReader in project alluxio by Alluxio.
the class LocalBlockInStream method create.
/**
* Creates a new local block input stream.
*
* @param blockId the block id
* @param blockSize the size of the block
* @param workerNetAddress the address of the local worker
* @param context the file system context
* @param options the instream options
* @return the {@link LocalBlockInStream} instance
* @throws IOException if I/O error occurs
*/
// TODO(peis): Use options idiom (ALLUXIO-2579).
public static LocalBlockInStream create(long blockId, long blockSize, WorkerNetAddress workerNetAddress, FileSystemContext context, InStreamOptions options) throws IOException {
Closer closer = Closer.create();
try {
BlockWorkerClient client = closer.register(context.createBlockWorkerClient(workerNetAddress));
LockBlockResult result = closer.register(client.lockBlock(blockId, LockBlockOptions.defaults())).getResult();
LocalFileBlockReader reader = closer.register(new LocalFileBlockReader(result.getBlockPath()));
return new LocalBlockInStream(client, blockId, blockSize, reader, closer, options);
} catch (AlluxioException | IOException e) {
CommonUtils.closeQuitely(closer);
throw CommonUtils.castToIOException(e);
}
}
use of alluxio.worker.block.io.LocalFileBlockReader in project alluxio by Alluxio.
the class DataServerBlockReadHandlerTest method mockReader.
@Override
protected void mockReader(long start) throws Exception {
mBlockReader = new LocalFileBlockReader(mFile);
Mockito.when(mBlockWorker.readBlockRemote(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(mBlockReader);
}
Aggregations