Search in sources :

Example 6 with AlluxioException

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

the class AlluxioFuseFileSystem method getattr.

/**
   * Retrieves file attributes.
   *
   * @param path The path on the FS of the file
   * @param stat FUSE data structure to fill with file attrs
   * @return 0 on success, negative value on error
   */
@Override
public int getattr(String path, FileStat stat) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    LOG.trace("getattr({}) [Alluxio: {}]", path, turi);
    try {
        if (!mFileSystem.exists(turi)) {
            return -ErrorCodes.ENOENT();
        }
        final URIStatus status = mFileSystem.getStatus(turi);
        stat.st_size.set(status.getLength());
        final long ctime_sec = status.getLastModificationTimeMs() / 1000;
        //keeps only the "residual" nanoseconds not caputred in
        // citme_sec
        final long ctime_nsec = (status.getLastModificationTimeMs() % 1000) * 1000;
        stat.st_ctim.tv_sec.set(ctime_sec);
        stat.st_ctim.tv_nsec.set(ctime_nsec);
        stat.st_mtim.tv_sec.set(ctime_sec);
        stat.st_mtim.tv_nsec.set(ctime_nsec);
        // TODO(andreareale): understand how to map FileInfo#getOwner()
        // and FileInfo#getGroup() to UIDs and GIDs of the node
        // where alluxio-fuse is mounted.
        // While this is not done, just use uid and gid of the user
        // running alluxio-fuse.
        stat.st_uid.set(UID_AND_GID[0]);
        stat.st_gid.set(UID_AND_GID[1]);
        final int mode;
        if (status.isFolder()) {
            mode = FileStat.S_IFDIR;
        } else {
            mode = FileStat.S_IFREG;
        }
        stat.st_mode.set(mode);
    } catch (InvalidPathException e) {
        LOG.debug("Invalid path {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (FileDoesNotExistException e) {
        LOG.debug("File does not exist {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (IOException e) {
        LOG.error("IOException on {}", path, e);
        return -ErrorCodes.EIO();
    } catch (AlluxioException e) {
        LOG.error("AlluxioException on {}", path, e);
        return -ErrorCodes.EFAULT();
    } catch (Throwable e) {
        LOG.error("Unexpected exception on {}", path, e);
        return -ErrorCodes.EFAULT();
    }
    return 0;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 7 with AlluxioException

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

the class AlluxioFuseFileSystem method rmInternal.

/**
   * Convenience internal method to remove files or directories.
   *
   * @param path The path to remove
   * @param mustBeFile When true, returns an error when trying to
   *                   remove a directory
   * @return 0 on success, a negative value on error
   */
private int rmInternal(String path, boolean mustBeFile) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    try {
        if (!mFileSystem.exists(turi)) {
            LOG.error("File {} does not exist", turi);
            return -ErrorCodes.ENOENT();
        }
        final URIStatus status = mFileSystem.getStatus(turi);
        if (mustBeFile && status.isFolder()) {
            LOG.error("File {} is a directory", turi);
            return -ErrorCodes.EISDIR();
        }
        mFileSystem.delete(turi);
    } catch (FileDoesNotExistException e) {
        LOG.debug("File does not exist {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (IOException e) {
        LOG.error("IOException on {}", path, e);
        return -ErrorCodes.EIO();
    } catch (AlluxioException e) {
        LOG.error("AlluxioException on {}", path, e);
        return -ErrorCodes.EFAULT();
    } catch (Throwable e) {
        LOG.error("Unexpected exception on {}", path, e);
        return -ErrorCodes.EFAULT();
    }
    return 0;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 8 with AlluxioException

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

the class KeyValueInputFormat method getSplits.

/**
   * Returns a list of {@link KeyValueInputSplit} where each split is one key-value partition.
   *
   * @param jobContext MapReduce job configuration
   * @return list of {@link InputSplit}s, each split is a partition
   * @throws IOException if information about the partition cannot be retrieved
   */
@Override
public List<InputSplit> getSplits(JobContext jobContext) throws IOException {
    // The paths are MapReduce program's inputs specified in
    // {@code mapreduce.input.fileinputformat.inputdir}, each path should be a key-value store.
    Path[] paths = FileInputFormat.getInputPaths(jobContext);
    List<InputSplit> splits = new ArrayList<>();
    try {
        for (Path path : paths) {
            List<PartitionInfo> partitionInfos = mKeyValueMasterClient.getPartitionInfo(new AlluxioURI(path.toString()));
            for (PartitionInfo partitionInfo : partitionInfos) {
                splits.add(new KeyValueInputSplit(partitionInfo));
            }
        }
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
    return splits;
}
Also used : Path(org.apache.hadoop.fs.Path) ArrayList(java.util.ArrayList) PartitionInfo(alluxio.thrift.PartitionInfo) IOException(java.io.IOException) InputSplit(org.apache.hadoop.mapreduce.InputSplit) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 9 with AlluxioException

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

the class KeyValueRecordReader method nextKeyValue.

@Override
public synchronized boolean nextKeyValue() throws IOException {
    if (!mKeyValuePairIterator.hasNext()) {
        return false;
    }
    KeyValuePair pair;
    try {
        pair = mKeyValuePairIterator.next();
    } catch (AlluxioException e) {
        throw new IOException(e);
    }
    // TODO(cc): Implement a ByteBufferInputStream which is backed by a ByteBuffer so we could
    // benefit from zero-copy.
    mCurrentKey.set(new BytesWritable(BufferUtils.newByteArrayFromByteBuffer(pair.getKey())));
    mCurrentValue.set(new BytesWritable(BufferUtils.newByteArrayFromByteBuffer(pair.getValue())));
    mNumVisitedKeyValuePairs++;
    return true;
}
Also used : KeyValuePair(alluxio.client.keyvalue.KeyValuePair) BytesWritable(org.apache.hadoop.io.BytesWritable) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Example 10 with AlluxioException

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

the class AlluxioFuseFileSystem method readdir.

/**
   * Reads the contents of a directory.
   *
   * @param path The FS path of the directory
   * @param buff The FUSE buffer to fill
   * @param filter FUSE filter
   * @param offset Ignored in alluxio-fuse
   * @param fi FileInfo data structure kept by FUSE
   * @return 0 on success, a negative value on error
   */
@Override
public int readdir(String path, Pointer buff, FuseFillDir filter, @off_t long offset, FuseFileInfo fi) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    LOG.trace("readdir({}) [Alluxio: {}]", path, turi);
    try {
        if (!mFileSystem.exists(turi)) {
            return -ErrorCodes.ENOENT();
        }
        final URIStatus status = mFileSystem.getStatus(turi);
        if (!status.isFolder()) {
            return -ErrorCodes.ENOTDIR();
        }
        final List<URIStatus> ls = mFileSystem.listStatus(turi);
        // standard . and .. entries
        filter.apply(buff, ".", null, 0);
        filter.apply(buff, "..", null, 0);
        for (final URIStatus file : ls) {
            filter.apply(buff, file.getName(), null, 0);
        }
    } catch (FileDoesNotExistException e) {
        LOG.debug("File does not exist {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (InvalidPathException e) {
        LOG.debug("Invalid path {}", path, e);
        return -ErrorCodes.ENOENT();
    } catch (IOException e) {
        LOG.error("IOException on {}", path, e);
        return -ErrorCodes.EIO();
    } catch (AlluxioException e) {
        LOG.error("AlluxioException on {}", path, e);
        return -ErrorCodes.EFAULT();
    } catch (Throwable e) {
        LOG.error("Unexpected exception on {}", path, e);
        return -ErrorCodes.EFAULT();
    }
    return 0;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) 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