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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations