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