Search in sources :

Example 51 with AlluxioException

use of alluxio.exception.AlluxioException in project alluxio by Alluxio.

the class KeyValueInputSplit method getLocations.

@Override
public String[] getLocations() throws IOException {
    try {
        List<BlockWorkerInfo> workersInfo = mBlockStore.getWorkerInfoList();
        int workersInfoSize = workersInfo.size();
        String[] locations = new String[workersInfoSize];
        for (int i = 0; i < workersInfoSize; i++) {
            locations[i] = workersInfo.get(i).getNetAddress().getHost();
        }
        return locations;
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
}
Also used : BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Example 52 with AlluxioException

use of alluxio.exception.AlluxioException in project alluxio by Alluxio.

the class KeyValueRecordReader method initialize.

@Override
public void initialize(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
    try {
        mReader = KeyValuePartitionReader.Factory.create(((KeyValueInputSplit) split).getPartitionId());
        mKeyValuePairIterator = mReader.iterator();
        mNumVisitedKeyValuePairs = 0;
        mNumKeyValuePairs = mReader.size();
        mCurrentKey = new BytesWritable();
        mCurrentValue = new BytesWritable();
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
}
Also used : BytesWritable(org.apache.hadoop.io.BytesWritable) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Example 53 with AlluxioException

use of alluxio.exception.AlluxioException in project alluxio by Alluxio.

the class AlluxioShellUtils method getAlluxioURIs.

/**
   * The utility function used to implement getAlluxioURIs.
   *
   * Basically, it recursively iterates through the directory from the parent directory of inputURI
   * (e.g., for input "/a/b/*", it will start from "/a/b") until it finds all the matches;
   * It does not go into a directory if the prefix mismatches
   * (e.g., for input "/a/b/*", it won't go inside directory "/a/c")
   *
   * @param alluxioClient the client used to fetch metadata of Alluxio files
   * @param inputURI the input URI (could contain wildcards)
   * @param parentDir the {@link AlluxioURI} of the directory in which we are searching matched
   *                  files
   * @return a list of {@link AlluxioURI}s of the files that match the inputURI in parentDir
   * @throws IOException if any filesystem errors are encountered when expanding paths with
   *                     wildcards
   */
private static List<AlluxioURI> getAlluxioURIs(FileSystem alluxioClient, AlluxioURI inputURI, AlluxioURI parentDir) throws IOException {
    List<AlluxioURI> res = new LinkedList<>();
    List<URIStatus> statuses;
    try {
        statuses = alluxioClient.listStatus(parentDir);
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
    for (URIStatus status : statuses) {
        AlluxioURI fileURI = new AlluxioURI(inputURI.getScheme(), inputURI.getAuthority(), status.getPath());
        if (match(fileURI, inputURI)) {
            // if it matches
            res.add(fileURI);
        } else {
            if (status.isFolder()) {
                // if it is a folder, we do it recursively
                AlluxioURI dirURI = new AlluxioURI(inputURI.getScheme(), inputURI.getAuthority(), status.getPath());
                String prefix = inputURI.getLeadingPath(dirURI.getDepth());
                if (prefix != null && match(dirURI, new AlluxioURI(prefix))) {
                    res.addAll(getAlluxioURIs(alluxioClient, inputURI, dirURI));
                }
            }
        }
    }
    return res;
}
Also used : IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) LinkedList(java.util.LinkedList) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 54 with AlluxioException

use of alluxio.exception.AlluxioException in project alluxio by Alluxio.

the class AlluxioBlockStore method promote.

/**
   * Attempts to promote a block in Alluxio space. If the block is not present, this method will
   * return without an error. If the block is present in multiple workers, only one worker will
   * receive the promotion request.
   *
   * @param blockId the id of the block to promote
   * @throws IOException if the block does not exist
   */
public void promote(long blockId) throws IOException {
    BlockInfo info;
    try (CloseableResource<BlockMasterClient> blockMasterClientResource = mContext.acquireBlockMasterClientResource()) {
        info = blockMasterClientResource.get().getBlockInfo(blockId);
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
    if (info.getLocations().isEmpty()) {
        // Nothing to promote
        return;
    }
    // Get the first worker address for now, as this will likely be the location being read from
    // TODO(calvin): Get this location via a policy (possibly location is a parameter to promote)
    BlockWorkerClient blockWorkerClient = mContext.createBlockWorkerClient(info.getLocations().get(0).getWorkerAddress(), null);
    try {
        blockWorkerClient.promoteBlock(blockId);
    } catch (AlluxioException e) {
        throw new IOException(e);
    } finally {
        blockWorkerClient.close();
    }
}
Also used : BlockInfo(alluxio.wire.BlockInfo) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Example 55 with AlluxioException

use of alluxio.exception.AlluxioException in project alluxio by Alluxio.

the class AbstractThriftClient method retryRPC.

/**
   * Similar to {@link #retryRPC(RpcCallable)} except that the RPC call may throw
   * {@link AlluxioTException} and once it is thrown, it will be transformed into
   * {@link AlluxioException} and be thrown.
   *
   * @param rpc the RPC call to be executed
   * @param <V> type of return value of the RPC call
   * @return the return value of the RPC call
   * @throws AlluxioException when {@link AlluxioTException} is thrown by the RPC call
   * @throws IOException when retries exceeds {@link #RPC_MAX_NUM_RETRY} or some server
   *         side IOException occurred.
   */
protected <V> V retryRPC(RpcCallableThrowsAlluxioTException<V, C> rpc) throws AlluxioException, IOException {
    TException exception = null;
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
    do {
        C client = acquireClient();
        try {
            return rpc.call(client);
        } catch (AlluxioTException e) {
            AlluxioException ae = AlluxioException.fromThrift(e);
            processException(client, ae);
            exception = new TException(ae);
        } catch (ThriftIOException e) {
            throw new IOException(e);
        } catch (TException e) {
            LOG.error(e.getMessage(), e);
            closeClient(client);
            exception = e;
        } finally {
            releaseClient(client);
        }
    } while (retryPolicy.attemptRetry());
    LOG.error("Failed after " + retryPolicy.getRetryCount() + " retries.");
    Preconditions.checkNotNull(exception);
    throw new IOException(exception);
}
Also used : AlluxioTException(alluxio.thrift.AlluxioTException) TException(org.apache.thrift.TException) AlluxioTException(alluxio.thrift.AlluxioTException) ThriftIOException(alluxio.thrift.ThriftIOException) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) ThriftIOException(alluxio.thrift.ThriftIOException) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy) AlluxioException(alluxio.exception.AlluxioException)

Aggregations

AlluxioException (alluxio.exception.AlluxioException)56 IOException (java.io.IOException)54 AlluxioURI (alluxio.AlluxioURI)33 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)15 URIStatus (alluxio.client.file.URIStatus)13 ArrayList (java.util.ArrayList)11 InvalidPathException (alluxio.exception.InvalidPathException)9 Closer (com.google.common.io.Closer)8 FileOutStream (alluxio.client.file.FileOutStream)5 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)5 WorkerNetAddress (alluxio.wire.WorkerNetAddress)5 LockBlockResult (alluxio.wire.LockBlockResult)4 BlockWorkerClient (alluxio.client.block.BlockWorkerClient)3 Mode (alluxio.security.authorization.Mode)3 AlluxioTException (alluxio.thrift.AlluxioTException)3 ThriftIOException (alluxio.thrift.ThriftIOException)3 File (java.io.File)3 WorkerStorageTierAssoc (alluxio.WorkerStorageTierAssoc)2 LockBlockOptions (alluxio.client.block.options.LockBlockOptions)2 SetAttributeOptions (alluxio.client.file.options.SetAttributeOptions)2