Search in sources :

Example 1 with BlockWorkerClient

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;
    }
}
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 BlockWorkerClient

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);
    }
}
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 BlockWorkerClient

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;
}
Also used : RemoveBlockRequest(alluxio.grpc.RemoveBlockRequest) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) NotFoundException(alluxio.exception.status.NotFoundException) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient)

Example 4 with BlockWorkerClient

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();
    }
}
Also used : FileSystemContext(alluxio.client.file.FileSystemContext) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 5 with BlockWorkerClient

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;
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) MoveBlockRequest(alluxio.grpc.MoveBlockRequest) NotFoundException(alluxio.exception.status.NotFoundException) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient)

Aggregations

BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)7 WorkerNetAddress (alluxio.wire.WorkerNetAddress)5 BlockInfo (alluxio.wire.BlockInfo)4 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)3 NotFoundException (alluxio.exception.status.NotFoundException)3 CacheRequest (alluxio.grpc.CacheRequest)3 IOException (java.io.IOException)3 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)2 InStreamOptions (alluxio.client.file.options.InStreamOptions)2 AlluxioException (alluxio.exception.AlluxioException)2 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)2 FileBlockInfo (alluxio.wire.FileBlockInfo)2 AlluxioURI (alluxio.AlluxioURI)1 BlockLocationPolicy (alluxio.client.block.policy.BlockLocationPolicy)1 LocalFirstPolicy (alluxio.client.block.policy.LocalFirstPolicy)1 TestBlockInStream (alluxio.client.block.stream.TestBlockInStream)1 FileSystemContext (alluxio.client.file.FileSystemContext)1 InvalidArgumentException (alluxio.exception.status.InvalidArgumentException)1 MoveBlockRequest (alluxio.grpc.MoveBlockRequest)1 RemoveBlockRequest (alluxio.grpc.RemoveBlockRequest)1