use of alluxio.grpc.CacheRequest 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.grpc.CacheRequest 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.grpc.CacheRequest in project alluxio by Alluxio.
the class CacheRequestManagerTest method submitAsyncRequestCacheBlockFromUfs.
@Test
public void submitAsyncRequestCacheBlockFromUfs() throws Exception {
CacheRequest request = CacheRequest.newBuilder().setBlockId(BLOCK_ID).setLength(CHUNK_SIZE).setOpenUfsBlockOptions(mOpenUfsBlockOptions).setSourceHost(mLocalWorkerHostname).setSourcePort(PORT).setAsync(true).build();
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 CacheRequestManagerTest method submitRequestCacheBlockFromRemoteWorker.
@Test
public void submitRequestCacheBlockFromRemoteWorker() throws Exception {
String fakeRemoteWorker = mLocalWorkerHostname + "1";
CacheRequest request = CacheRequest.newBuilder().setBlockId(BLOCK_ID).setLength(CHUNK_SIZE).setOpenUfsBlockOptions(mOpenUfsBlockOptions).setSourceHost(fakeRemoteWorker).setSourcePort(PORT).build();
setupMockRemoteReader(fakeRemoteWorker, PORT, BLOCK_ID, CHUNK_SIZE, mOpenUfsBlockOptions);
mCacheRequestManager.submitRequest(request);
assertTrue(mBlockWorker.hasBlockMeta(BLOCK_ID));
}
use of alluxio.grpc.CacheRequest in project alluxio by Alluxio.
the class CacheRequestManagerTest method submitRequestCacheBlockFromUfs.
@Test
public void submitRequestCacheBlockFromUfs() throws Exception {
CacheRequest request = CacheRequest.newBuilder().setBlockId(BLOCK_ID).setLength(CHUNK_SIZE).setOpenUfsBlockOptions(mOpenUfsBlockOptions).setSourceHost(mLocalWorkerHostname).setSourcePort(PORT).build();
mCacheRequestManager.submitRequest(request);
assertTrue(mBlockWorker.hasBlockMeta(BLOCK_ID));
}
Aggregations