Search in sources :

Example 1 with CacheRequest

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;
    }
}
Also used : CacheRequest(alluxio.grpc.CacheRequest) BlockInfo(alluxio.wire.BlockInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with CacheRequest

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);
    }
}
Also used : CacheRequest(alluxio.grpc.CacheRequest) BlockInfo(alluxio.wire.BlockInfo) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException)

Example 3 with CacheRequest

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));
}
Also used : CacheRequest(alluxio.grpc.CacheRequest) Test(org.junit.Test)

Example 4 with CacheRequest

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));
}
Also used : CacheRequest(alluxio.grpc.CacheRequest) Test(org.junit.Test)

Example 5 with CacheRequest

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));
}
Also used : CacheRequest(alluxio.grpc.CacheRequest) Test(org.junit.Test)

Aggregations

CacheRequest (alluxio.grpc.CacheRequest)7 Test (org.junit.Test)4 BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)3 BlockInfo (alluxio.wire.BlockInfo)3 IOException (java.io.IOException)3 AlluxioException (alluxio.exception.AlluxioException)2 WorkerNetAddress (alluxio.wire.WorkerNetAddress)2 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)1 BlockLocationPolicy (alluxio.client.block.policy.BlockLocationPolicy)1 LocalFirstPolicy (alluxio.client.block.policy.LocalFirstPolicy)1 InStreamOptions (alluxio.client.file.options.InStreamOptions)1 InvalidArgumentException (alluxio.exception.status.InvalidArgumentException)1 NotFoundException (alluxio.exception.status.NotFoundException)1 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)1 Protocol (alluxio.proto.dataserver.Protocol)1 FileBlockInfo (alluxio.wire.FileBlockInfo)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1