Search in sources :

Example 6 with CephStat

use of com.ceph.fs.CephStat in project alluxio by Alluxio.

the class CephFSUnderFileSystem method isDirectory.

@Override
public boolean isDirectory(String path) throws IOException {
    path = stripPath(path);
    try {
        CephStat stat = new CephStat();
        lstat(path, stat);
        return stat.isDir();
    } catch (FileNotFoundException e) {
        return false;
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) CephStat(com.ceph.fs.CephStat)

Example 7 with CephStat

use of com.ceph.fs.CephStat in project alluxio by Alluxio.

the class CephFSUnderFileSystem method openInternal.

private int openInternal(String path, int flags, int mode) throws IOException {
    int fd = mMount.open(path, flags, mode);
    CephStat stat = new CephStat();
    mMount.fstat(fd, stat);
    if (stat.isDir()) {
        mMount.close(fd);
        throw new FileNotFoundException();
    }
    return fd;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) CephStat(com.ceph.fs.CephStat)

Example 8 with CephStat

use of com.ceph.fs.CephStat in project alluxio by Alluxio.

the class CephFSUnderFileSystem method getBlockSizeByte.

@Override
public long getBlockSizeByte(String path) throws IOException {
    path = stripPath(path);
    CephStat stat = new CephStat();
    lstat(path, stat);
    return stat.blksize;
}
Also used : CephStat(com.ceph.fs.CephStat)

Example 9 with CephStat

use of com.ceph.fs.CephStat in project alluxio by Alluxio.

the class CephFSUnderFileSystem method rename.

/**
 * Rename a file or folder to a file or folder.
 *
 * @param src path of source file or directory
 * @param dst path of destination file or directory
 * @return true if rename succeeds
 */
private boolean rename(String src, String dst) throws IOException {
    src = stripPath(src);
    dst = stripPath(dst);
    IOException te = null;
    RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
    while (retryPolicy.attempt()) {
        try {
            try {
                CephStat stat = new CephStat();
                lstat(dst, stat);
                if (stat.isDir()) {
                    String fileName = getFileName(src);
                    mMount.rename(src, PathUtils.concatPath(dst, fileName));
                    return true;
                }
                return false;
            } catch (FileNotFoundException e) {
            // can be ignored safely
            }
            mMount.rename(src, dst);
            return true;
        } catch (IOException e) {
            LOG.warn("{} try to rename {} to {} : {}", retryPolicy.getAttemptCount(), src, dst, e.toString());
            te = e;
        }
    }
    throw te;
}
Also used : CountingRetry(alluxio.retry.CountingRetry) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy) CephStat(com.ceph.fs.CephStat)

Example 10 with CephStat

use of com.ceph.fs.CephStat in project alluxio by Alluxio.

the class CephFSUnderFileSystem method open.

@Override
public InputStream open(String path, OpenOptions options) throws IOException {
    path = stripPath(path);
    IOException te = null;
    RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
    while (retryPolicy.attempt()) {
        try {
            int mode = CreateOptions.defaults(mUfsConf).getMode().toShort();
            int fd = openInternal(path, CephMount.O_RDONLY, mode);
            CephStat stat = new CephStat();
            mMount.fstat(fd, stat);
            CephInputStream inputStream = new CephInputStream(mMount, fd, stat.size);
            try {
                inputStream.seek(options.getOffset());
            } catch (IOException e) {
                inputStream.close();
                throw e;
            }
            return new CephSeekableInputStream(inputStream);
        } catch (IOException e) {
            LOG.warn("{} try to open {} : {}", retryPolicy.getAttemptCount(), path, e.toString());
            te = e;
        }
    }
    throw te;
}
Also used : CountingRetry(alluxio.retry.CountingRetry) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy) CephStat(com.ceph.fs.CephStat)

Aggregations

CephStat (com.ceph.fs.CephStat)12 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)4 CountingRetry (alluxio.retry.CountingRetry)2 RetryPolicy (alluxio.retry.RetryPolicy)2 UfsDirectoryStatus (alluxio.underfs.UfsDirectoryStatus)2 UfsFileStatus (alluxio.underfs.UfsFileStatus)2 UfsStatus (alluxio.underfs.UfsStatus)1 Nullable (javax.annotation.Nullable)1