Search in sources :

Example 1 with RemoveBlockRequest

use of alluxio.grpc.RemoveBlockRequest 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)

Aggregations

BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)1 BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)1 NotFoundException (alluxio.exception.status.NotFoundException)1 RemoveBlockRequest (alluxio.grpc.RemoveBlockRequest)1 WorkerNetAddress (alluxio.wire.WorkerNetAddress)1