Search in sources :

Example 1 with CountingRetry

use of alluxio.retry.CountingRetry in project alluxio by Alluxio.

the class HdfsUnderFileSystem 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
   * @throws IOException
   */
private boolean rename(String src, String dst) throws IOException {
    IOException te = null;
    RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
    while (retryPolicy.attemptRetry()) {
        try {
            return mFileSystem.rename(new Path(src), new Path(dst));
        } catch (IOException e) {
            LOG.error("{} try to rename {} to {} : {}", retryPolicy.getRetryCount(), src, dst, e.getMessage(), e);
            te = e;
        }
    }
    throw te;
}
Also used : Path(org.apache.hadoop.fs.Path) CountingRetry(alluxio.retry.CountingRetry) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy)

Example 2 with CountingRetry

use of alluxio.retry.CountingRetry in project alluxio by Alluxio.

the class HdfsUnderFileSystem method open.

@Override
public InputStream open(String path, OpenOptions options) throws IOException {
    IOException te = null;
    RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
    while (retryPolicy.attemptRetry()) {
        try {
            FSDataInputStream inputStream = mFileSystem.open(new Path(path));
            try {
                inputStream.seek(options.getOffset());
            } catch (IOException e) {
                inputStream.close();
                throw e;
            }
            return new HdfsUnderFileInputStream(inputStream);
        } catch (IOException e) {
            LOG.error("{} try to open {} : {}", retryPolicy.getRetryCount(), path, e.getMessage(), e);
            te = e;
        }
    }
    throw te;
}
Also used : Path(org.apache.hadoop.fs.Path) CountingRetry(alluxio.retry.CountingRetry) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy)

Example 3 with CountingRetry

use of alluxio.retry.CountingRetry in project alluxio by Alluxio.

the class HdfsUnderFileSystem method createDirect.

@Override
public OutputStream createDirect(String path, CreateOptions options) throws IOException {
    IOException te = null;
    RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
    while (retryPolicy.attemptRetry()) {
        try {
            LOG.debug("Creating HDFS file at {} with owner {}, group {}, mode {}", path, options.getOwner(), options.getGroup(), options.getMode());
            // TODO(chaomin): support creating HDFS files with specified block size and replication.
            return FileSystem.create(mFileSystem, new Path(path), new FsPermission(options.getMode().toShort()));
        } catch (IOException e) {
            LOG.error("Retry count {} : {} ", retryPolicy.getRetryCount(), e.getMessage(), e);
            te = e;
        }
    }
    throw te;
}
Also used : Path(org.apache.hadoop.fs.Path) CountingRetry(alluxio.retry.CountingRetry) IOException(java.io.IOException) FsPermission(org.apache.hadoop.fs.permission.FsPermission) RetryPolicy(alluxio.retry.RetryPolicy)

Example 4 with CountingRetry

use of alluxio.retry.CountingRetry in project alluxio by Alluxio.

the class HdfsUnderFileSystem method getFileSize.

@Override
public long getFileSize(String path) throws IOException {
    Path tPath = new Path(path);
    RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
    while (retryPolicy.attemptRetry()) {
        try {
            FileStatus fs = mFileSystem.getFileStatus(tPath);
            return fs.getLen();
        } catch (IOException e) {
            LOG.error("{} try to get file size for {} : {}", retryPolicy.getRetryCount(), path, e.getMessage(), e);
        }
    }
    return -1;
}
Also used : Path(org.apache.hadoop.fs.Path) CountingRetry(alluxio.retry.CountingRetry) FileStatus(org.apache.hadoop.fs.FileStatus) UnderFileStatus(alluxio.underfs.UnderFileStatus) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy)

Example 5 with CountingRetry

use of alluxio.retry.CountingRetry in project alluxio by Alluxio.

the class HdfsUnderFileSystem method delete.

/**
   * Delete a file or directory at path.
   *
   * @param path file or directory path
   * @param recursive whether to delete path recursively
   * @return true, if succeed
   * @throws IOException when a non-alluxio error occurs
   */
private boolean delete(String path, boolean recursive) throws IOException {
    LOG.debug("deleting {} {}", path, recursive);
    IOException te = null;
    RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
    while (retryPolicy.attemptRetry()) {
        try {
            return mFileSystem.delete(new Path(path), recursive);
        } catch (IOException e) {
            LOG.error("Retry count {} : {}", retryPolicy.getRetryCount(), e.getMessage(), e);
            te = e;
        }
    }
    throw te;
}
Also used : Path(org.apache.hadoop.fs.Path) CountingRetry(alluxio.retry.CountingRetry) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy)

Aggregations

CountingRetry (alluxio.retry.CountingRetry)8 IOException (java.io.IOException)8 RetryPolicy (alluxio.retry.RetryPolicy)6 Path (org.apache.hadoop.fs.Path)6 AlluxioException (alluxio.exception.AlluxioException)2 ExponentialBackoffRetry (alluxio.retry.ExponentialBackoffRetry)2 AlluxioTException (alluxio.thrift.AlluxioTException)2 ThriftIOException (alluxio.thrift.ThriftIOException)2 FsPermission (org.apache.hadoop.fs.permission.FsPermission)2 TException (org.apache.thrift.TException)2 UfsBlockAccessTokenUnavailableException (alluxio.exception.UfsBlockAccessTokenUnavailableException)1 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)1 UnderFileStatus (alluxio.underfs.UnderFileStatus)1 Stack (java.util.Stack)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FileStatus (org.apache.hadoop.fs.FileStatus)1