Search in sources :

Example 6 with NotFoundException

use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.

the class UfsFallbackBlockWriteHandler method transferToUfsBlock.

/**
 * Transfers data from block store to UFS.
 *
 * @param context context of this request
 * @param pos number of bytes in block store to write in the UFS block
 */
private void transferToUfsBlock(BlockWriteRequestContext context, long pos) throws Exception {
    OutputStream ufsOutputStream = context.getOutputStream();
    long sessionId = context.getRequest().getSessionId();
    long blockId = context.getRequest().getId();
    TempBlockMeta block = mWorker.getTempBlockMeta(sessionId, blockId);
    if (block == null) {
        throw new NotFoundException("block " + blockId + " not found");
    }
    Preconditions.checkState(Files.copy(Paths.get(block.getPath()), ufsOutputStream) == pos);
}
Also used : OutputStream(java.io.OutputStream) NotFoundException(alluxio.exception.status.NotFoundException) TempBlockMeta(alluxio.worker.block.meta.TempBlockMeta)

Example 7 with NotFoundException

use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.

the class JobUfsManager method get.

@Override
public UfsClient get(long mountId) throws NotFoundException, UnavailableException {
    try {
        return super.get(mountId);
    } catch (NotFoundException e) {
    // Not cached locally, let's query master
    }
    UfsInfo info;
    try {
        info = mMasterClient.getUfsInfo(mountId);
    } catch (IOException e) {
        throw new UnavailableException(String.format("Failed to create UFS info for mount point with id %d", mountId), e);
    }
    Preconditions.checkState((info.hasUri() && info.hasProperties()), "unknown mountId");
    super.addMount(mountId, new AlluxioURI(info.getUri()), UnderFileSystemConfiguration.defaults(ServerConfiguration.global()).setReadOnly(info.getProperties().getReadOnly()).setShared(info.getProperties().getShared()).createMountSpecificConf(info.getProperties().getPropertiesMap()));
    UfsClient ufsClient = super.get(mountId);
    try (CloseableResource<UnderFileSystem> ufsResource = ufsClient.acquireUfsResource()) {
        UnderFileSystem ufs = ufsResource.get();
        ufs.connectFromWorker(NetworkAddressUtils.getConnectHost(NetworkAddressUtils.ServiceType.WORKER_RPC, ServerConfiguration.global()));
    } catch (IOException e) {
        removeMount(mountId);
        throw new UnavailableException(String.format("Failed to connect to UFS %s with id %d", info.getUri(), mountId), e);
    }
    return ufsClient;
}
Also used : UfsInfo(alluxio.grpc.UfsInfo) UnavailableException(alluxio.exception.status.UnavailableException) NotFoundException(alluxio.exception.status.NotFoundException) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI)

Example 8 with NotFoundException

use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.

the class JobUtils method loadBlock.

/**
 * Loads a block into the local worker. If the block doesn't exist in Alluxio, it will be read
 * from the UFS.
 * @param status the uriStatus
 * @param context filesystem context
 * @param blockId the id of the block to load
 * @param address specify a worker to load into
 * @param directCache Use passive-cache or direct cache request
 */
public static void loadBlock(URIStatus status, FileSystemContext context, long blockId, WorkerNetAddress address, boolean directCache) throws AlluxioException, IOException {
    AlluxioConfiguration conf = ServerConfiguration.global();
    // Explicitly specified a worker to load
    WorkerNetAddress localNetAddress = address;
    String localHostName = NetworkAddressUtils.getConnectHost(ServiceType.WORKER_RPC, conf);
    List<WorkerNetAddress> netAddress = context.getCachedWorkers().stream().map(BlockWorkerInfo::getNetAddress).filter(x -> Objects.equals(x.getHost(), localHostName)).collect(Collectors.toList());
    if (localNetAddress == null && !netAddress.isEmpty()) {
        localNetAddress = netAddress.get(0);
    }
    if (localNetAddress == null) {
        throw new NotFoundException(ExceptionMessage.NO_LOCAL_BLOCK_WORKER_LOAD_TASK.getMessage(blockId));
    }
    Set<String> pinnedLocation = status.getPinnedMediumTypes();
    if (pinnedLocation.size() > 1) {
        throw new AlluxioException(ExceptionMessage.PINNED_TO_MULTIPLE_MEDIUMTYPES.getMessage(status.getPath()));
    }
    // Only use this read local first method to load if nearest worker is clear
    if (netAddress.size() <= 1 && pinnedLocation.isEmpty() && status.isPersisted()) {
        if (directCache) {
            loadThroughCacheRequest(status, context, blockId, conf, localNetAddress);
        } else {
            loadThroughRead(status, context, blockId, conf);
        }
        return;
    }
    // TODO(bin): remove the following case when we consolidate tier and medium
    // since there is only one element in the set, we take the first element in the set
    String medium = pinnedLocation.isEmpty() ? "" : pinnedLocation.iterator().next();
    OpenFilePOptions openOptions = OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build();
    InStreamOptions inOptions = new InStreamOptions(status, openOptions, conf);
    // Set read location policy always to local first for loading blocks for job tasks
    inOptions.setUfsReadLocationPolicy(BlockLocationPolicy.Factory.create(LocalFirstPolicy.class.getCanonicalName(), conf));
    OutStreamOptions outOptions = OutStreamOptions.defaults(context.getClientContext());
    outOptions.setMediumType(medium);
    // Set write location policy always to local first for loading blocks for job tasks
    outOptions.setLocationPolicy(BlockLocationPolicy.Factory.create(LocalFirstPolicy.class.getCanonicalName(), conf));
    BlockInfo blockInfo = status.getBlockInfo(blockId);
    Preconditions.checkNotNull(blockInfo, "Can not find block %s in status %s", blockId, status);
    long blockSize = blockInfo.getLength();
    AlluxioBlockStore blockStore = AlluxioBlockStore.create(context);
    try (OutputStream outputStream = blockStore.getOutStream(blockId, blockSize, localNetAddress, outOptions)) {
        try (InputStream inputStream = blockStore.getInStream(blockId, inOptions)) {
            ByteStreams.copy(inputStream, outputStream);
        } catch (Throwable t) {
            try {
                ((Cancelable) outputStream).cancel();
            } catch (Throwable t2) {
                t.addSuppressed(t2);
            }
            throw t;
        }
    }
}
Also used : Cancelable(alluxio.client.Cancelable) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) NetworkAddressUtils(alluxio.util.network.NetworkAddressUtils) FileBlockInfo(alluxio.wire.FileBlockInfo) PropertyKey(alluxio.conf.PropertyKey) ConcurrentMap(java.util.concurrent.ConcurrentMap) LocalFirstPolicy(alluxio.client.block.policy.LocalFirstPolicy) Constants(alluxio.Constants) CloseableResource(alluxio.resource.CloseableResource) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) ReadPType(alluxio.grpc.ReadPType) IndexDefinition(alluxio.collections.IndexDefinition) ServiceType(alluxio.util.network.NetworkAddressUtils.ServiceType) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient) OutputStream(java.io.OutputStream) Protocol(alluxio.proto.dataserver.Protocol) IndexedSet(alluxio.collections.IndexedSet) ServerConfiguration(alluxio.conf.ServerConfiguration) ImmutableMap(com.google.common.collect.ImmutableMap) CacheRequest(alluxio.grpc.CacheRequest) BlockInStream(alluxio.client.block.stream.BlockInStream) InStreamOptions(alluxio.client.file.options.InStreamOptions) ExceptionMessage(alluxio.exception.ExceptionMessage) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) Set(java.util.Set) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) Pair(alluxio.collections.Pair) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) NotFoundException(alluxio.exception.status.NotFoundException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) AlluxioProperties(alluxio.conf.AlluxioProperties) Objects(java.util.Objects) BlockLocation(alluxio.wire.BlockLocation) URIStatus(alluxio.client.file.URIStatus) List(java.util.List) FileSystemContext(alluxio.client.file.FileSystemContext) ByteStreams(com.google.common.io.ByteStreams) Preconditions(com.google.common.base.Preconditions) InstancedConfiguration(alluxio.conf.InstancedConfiguration) InputStream(java.io.InputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) NotFoundException(alluxio.exception.status.NotFoundException) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) InStreamOptions(alluxio.client.file.options.InStreamOptions) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) AlluxioException(alluxio.exception.AlluxioException)

Example 9 with NotFoundException

use of alluxio.exception.status.NotFoundException 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 10 with NotFoundException

use of alluxio.exception.status.NotFoundException in project alluxio by Alluxio.

the class AbstractClient method connect.

/**
 * Connects with the remote.
 */
@Override
public synchronized void connect() throws AlluxioStatusException {
    if (mConnected) {
        return;
    }
    disconnect();
    Preconditions.checkState(!mClosed, "Client is closed, will not try to connect.");
    IOException lastConnectFailure = null;
    RetryPolicy retryPolicy = mRetryPolicySupplier.get();
    while (retryPolicy.attempt()) {
        if (mClosed) {
            throw new FailedPreconditionException("Failed to connect: client has been closed");
        }
        // failover).
        try {
            mAddress = getAddress();
        } catch (UnavailableException e) {
            LOG.debug("Failed to determine {} rpc address ({}): {}", getServiceName(), retryPolicy.getAttemptCount(), e.toString());
            continue;
        }
        try {
            beforeConnect();
            LOG.debug("Alluxio client (version {}) is trying to connect with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress);
            mChannel = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(mAddress), mContext.getClusterConf()).setSubject(mContext.getSubject()).setClientType(getServiceName()).build();
            // Create stub for version service on host
            mVersionService = ServiceVersionClientServiceGrpc.newBlockingStub(mChannel);
            mConnected = true;
            afterConnect();
            checkVersion(getServiceVersion());
            LOG.debug("Alluxio client (version {}) is connected with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress);
            return;
        } catch (IOException e) {
            LOG.debug("Failed to connect ({}) with {} @ {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e);
            lastConnectFailure = e;
            if (e instanceof UnauthenticatedException) {
                // If there has been a failure in opening GrpcChannel, it's possible because
                // the authentication credential has expired. Relogin.
                mContext.getUserState().relogin();
            }
            if (e instanceof NotFoundException) {
                // service is not found in the server, skip retry
                break;
            }
        }
    }
    if (mChannel != null) {
        mChannel.shutdown();
    }
    if (mAddress == null) {
        throw new UnavailableException(String.format("Failed to determine address for %s after %s attempts", getServiceName(), retryPolicy.getAttemptCount()));
    }
    /*
     * Throw as-is if {@link UnauthenticatedException} occurred.
     */
    if (lastConnectFailure instanceof UnauthenticatedException) {
        throw (AlluxioStatusException) lastConnectFailure;
    }
    if (lastConnectFailure instanceof NotFoundException) {
        throw new NotFoundException(lastConnectFailure.getMessage(), new ServiceNotFoundException(lastConnectFailure.getMessage(), lastConnectFailure));
    }
    throw new UnavailableException(String.format("Failed to connect to master (%s) after %s attempts." + "Please check if Alluxio master is currently running on \"%s\". Service=\"%s\"", mAddress, retryPolicy.getAttemptCount(), mAddress, getServiceName()), lastConnectFailure);
}
Also used : UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) ServiceNotFoundException(alluxio.exception.ServiceNotFoundException) FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) UnavailableException(alluxio.exception.status.UnavailableException) NotFoundException(alluxio.exception.status.NotFoundException) ServiceNotFoundException(alluxio.exception.ServiceNotFoundException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy)

Aggregations

NotFoundException (alluxio.exception.status.NotFoundException)20 IOException (java.io.IOException)9 AlluxioURI (alluxio.AlluxioURI)6 UnavailableException (alluxio.exception.status.UnavailableException)6 WorkerNetAddress (alluxio.wire.WorkerNetAddress)5 List (java.util.List)4 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)3 BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)3 BlockInStream (alluxio.client.block.stream.BlockInStream)2 URIStatus (alluxio.client.file.URIStatus)2 InStreamOptions (alluxio.client.file.options.InStreamOptions)2 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)2 AlluxioException (alluxio.exception.AlluxioException)2 UfsInfo (alluxio.grpc.UfsInfo)2 ColumnStatisticsInfo (alluxio.grpc.table.ColumnStatisticsInfo)2 Layout (alluxio.grpc.table.Layout)2 PartitionInfo (alluxio.grpc.table.layout.hive.PartitionInfo)2 MasterWorkerInfo (alluxio.master.block.meta.MasterWorkerInfo)2 LockResource (alluxio.resource.LockResource)2 UdbPartition (alluxio.table.common.UdbPartition)2