use of alluxio.client.block.stream.BlockWorkerClient in project alluxio by Alluxio.
the class AlluxioFileInStream method triggerAsyncCaching.
// Send an async cache request to a worker based on read type and passive cache options.
// Note that, this is best effort
@VisibleForTesting
boolean triggerAsyncCaching(BlockInStream stream) {
final long blockId = stream.getId();
final BlockInfo blockInfo = mStatus.getBlockInfo(blockId);
if (blockInfo == null) {
return false;
}
try {
boolean cache = ReadType.fromProto(mOptions.getOptions().getReadType()).isCache();
boolean overReplicated = mStatus.getReplicationMax() > 0 && blockInfo.getLocations().size() >= mStatus.getReplicationMax();
cache = cache && !overReplicated;
// Get relevant information from the stream.
WorkerNetAddress dataSource = stream.getAddress();
if (cache && (mLastBlockIdCached != blockId)) {
// Construct the async cache request
long blockLength = mOptions.getBlockInfo(blockId).getLength();
String host = dataSource.getHost();
// to establish the connection.
if (!dataSource.getContainerHost().equals("")) {
LOG.debug("Worker is in a container. Use container host {} instead of physical host {}", dataSource.getContainerHost(), host);
host = dataSource.getContainerHost();
}
CacheRequest request = CacheRequest.newBuilder().setBlockId(blockId).setLength(blockLength).setOpenUfsBlockOptions(mOptions.getOpenUfsBlockOptions(blockId)).setSourceHost(host).setSourcePort(dataSource.getDataPort()).setAsync(true).build();
if (mPassiveCachingEnabled && mContext.hasProcessLocalWorker()) {
mContext.getProcessLocalWorker().cache(request);
mLastBlockIdCached = blockId;
return true;
}
WorkerNetAddress worker;
if (mPassiveCachingEnabled && mContext.hasNodeLocalWorker()) {
// send request to local worker
worker = mContext.getNodeLocalWorker();
} else {
// send request to data source
worker = dataSource;
}
try (CloseableResource<BlockWorkerClient> blockWorker = mContext.acquireBlockWorkerClient(worker)) {
blockWorker.get().cache(request);
mLastBlockIdCached = blockId;
}
}
return true;
} catch (Exception e) {
LOG.warn("Failed to complete async cache request (best effort) for block {} of file {}: {}", stream.getId(), mStatus.getPath(), e.toString());
return false;
}
}
use of alluxio.client.block.stream.BlockWorkerClient in project alluxio by Alluxio.
the class LoadCommand method cacheBlock.
private void cacheBlock(long blockId, WorkerNetAddress dataSource, URIStatus status, Protocol.OpenUfsBlockOptions options) {
BlockInfo info = status.getBlockInfo(blockId);
long blockLength = info.getLength();
String host = dataSource.getHost();
// to establish the connection.
if (!dataSource.getContainerHost().equals("")) {
host = dataSource.getContainerHost();
}
CacheRequest request = CacheRequest.newBuilder().setBlockId(blockId).setLength(blockLength).setOpenUfsBlockOptions(options).setSourceHost(host).setSourcePort(dataSource.getDataPort()).build();
try (CloseableResource<BlockWorkerClient> blockWorker = mFsContext.acquireBlockWorkerClient(dataSource)) {
blockWorker.get().cache(request);
} catch (Exception e) {
System.out.printf("Failed to complete cache request for block %d of file %s: %s", blockId, status.getPath(), e);
}
}
use of alluxio.client.block.stream.BlockWorkerClient in project alluxio by Alluxio.
the class EvictDefinition method runTask.
/**
* {@inheritDoc}
*
* This task will evict the given block.
*/
@Override
public SerializableVoid runTask(EvictConfig config, SerializableVoid args, RunTaskContext context) throws Exception {
long blockId = config.getBlockId();
String localHostName = NetworkAddressUtils.getConnectHost(ServiceType.WORKER_RPC, ServerConfiguration.global());
List<BlockWorkerInfo> workerInfoList = context.getFsContext().getCachedWorkers();
WorkerNetAddress localNetAddress = null;
for (BlockWorkerInfo workerInfo : workerInfoList) {
if (workerInfo.getNetAddress().getHost().equals(localHostName)) {
localNetAddress = workerInfo.getNetAddress();
break;
}
}
if (localNetAddress == null) {
String message = String.format("Cannot find a local block worker to evict block %d", blockId);
throw new NotFoundException(message);
}
RemoveBlockRequest request = RemoveBlockRequest.newBuilder().setBlockId(blockId).build();
try (CloseableResource<BlockWorkerClient> blockWorker = context.getFsContext().acquireBlockWorkerClient(localNetAddress)) {
blockWorker.get().removeBlock(request);
} catch (NotFoundException e) {
// Instead of throwing this exception, we continue here because the block to evict does not
// exist on this worker anyway.
LOG.warn("Failed to delete block {} on {}: block does not exist", blockId, localNetAddress);
}
return null;
}
use of alluxio.client.block.stream.BlockWorkerClient in project alluxio by Alluxio.
the class FileSystemContextReinitIntegrationTest method blockWorkerClientReinit.
@Test
public void blockWorkerClientReinit() throws Exception {
FileSystemContext fsContext = FileSystemContext.create(ServerConfiguration.global());
try (CloseableResource<BlockWorkerClient> client = fsContext.acquireBlockWorkerClient(mLocalAlluxioClusterResource.get().getWorkerAddress())) {
fsContext.reinit(true, true);
fsContext.acquireBlockWorkerClient(mLocalAlluxioClusterResource.get().getWorkerAddress()).close();
}
}
use of alluxio.client.block.stream.BlockWorkerClient in project alluxio by Alluxio.
the class MoveDefinition method runTask.
/**
* {@inheritDoc}
*
* This task will move the given block.
*/
@Override
public SerializableVoid runTask(MoveConfig config, SerializableVoid args, RunTaskContext context) throws Exception {
long blockId = config.getBlockId();
String localHostName = NetworkAddressUtils.getConnectHost(ServiceType.WORKER_RPC, ServerConfiguration.global());
List<BlockWorkerInfo> workerInfoList = context.getFsContext().getCachedWorkers();
WorkerNetAddress localNetAddress = null;
for (BlockWorkerInfo workerInfo : workerInfoList) {
if (workerInfo.getNetAddress().getHost().equals(localHostName)) {
localNetAddress = workerInfo.getNetAddress();
break;
}
}
if (localNetAddress == null) {
String message = String.format("Cannot find a local block worker to move block %d", blockId);
throw new NotFoundException(message);
}
MoveBlockRequest request = MoveBlockRequest.newBuilder().setBlockId(blockId).setMediumType(config.getMediumType()).build();
try (CloseableResource<BlockWorkerClient> blockWorker = context.getFsContext().acquireBlockWorkerClient(localNetAddress)) {
blockWorker.get().moveBlock(request);
}
return null;
}
Aggregations