use of alluxio.retry.RetryPolicy 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.RetryPolicy 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;
}
use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.
the class HdfsUnderFileSystem method mkdirs.
@Override
public boolean mkdirs(String path, MkdirsOptions options) throws IOException {
IOException te = null;
RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
while (retryPolicy.attemptRetry()) {
try {
Path hdfsPath = new Path(path);
if (mFileSystem.exists(hdfsPath)) {
LOG.debug("Trying to create existing directory at {}", path);
return false;
}
// Create directories one by one with explicit permissions to ensure no umask is applied,
// using mkdirs will apply the permission only to the last directory
Stack<Path> dirsToMake = new Stack<>();
dirsToMake.push(hdfsPath);
Path parent = hdfsPath.getParent();
while (!mFileSystem.exists(parent)) {
dirsToMake.push(parent);
parent = parent.getParent();
}
while (!dirsToMake.empty()) {
Path dirToMake = dirsToMake.pop();
if (!FileSystem.mkdirs(mFileSystem, dirToMake, new FsPermission(options.getMode().toShort()))) {
return false;
}
// proceeds with mkdirs and print out an warning message.
try {
setOwner(dirToMake.toString(), options.getOwner(), options.getGroup());
} catch (IOException e) {
LOG.warn("Failed to update the ufs dir ownership, default values will be used. " + e);
}
}
return true;
} catch (IOException e) {
LOG.error("{} try to make directory for {} : {}", retryPolicy.getRetryCount(), path, e.getMessage(), e);
te = e;
}
}
throw te;
}
use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.
the class RetryHandlingBlockWorkerClient method lockUfsBlock.
@Override
public LockBlockResource lockUfsBlock(final long blockId, final LockBlockOptions options) throws IOException, AlluxioException {
int retryInterval = Constants.SECOND_MS;
RetryPolicy retryPolicy = new TimeoutRetry(Configuration.getLong(PropertyKey.USER_UFS_BLOCK_OPEN_TIMEOUT_MS), retryInterval);
do {
LockBlockResource resource = lockBlock(blockId, options);
if (resource.getResult().getLockBlockStatus().ufsTokenNotAcquired()) {
LOG.debug("Failed to acquire a UFS read token because of contention for block {} with " + "LockBlockOptions {}", blockId, options);
} else {
return resource;
}
} while (retryPolicy.attemptRetry());
throw new UfsBlockAccessTokenUnavailableException(ExceptionMessage.UFS_BLOCK_ACCESS_TOKEN_UNAVAILABLE, blockId, options.getUfsPath());
}
use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.
the class AbstractClient method connect.
/**
* Connects with the remote.
*
* @throws IOException if an I/O error occurs
* @throws ConnectionFailedException if network connection failed
*/
public synchronized void connect() throws IOException, ConnectionFailedException {
if (mConnected) {
return;
}
disconnect();
Preconditions.checkState(!mClosed, "Client is closed, will not try to connect.");
RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
while (!mClosed) {
mAddress = getAddress();
LOG.info("Alluxio client (version {}) is trying to connect with {} {} @ {}", RuntimeConstants.VERSION, getServiceName(), mMode, mAddress);
TProtocol binaryProtocol = new TBinaryProtocol(mTransportProvider.getClientTransport(mParentSubject, mAddress));
mProtocol = new TMultiplexedProtocol(binaryProtocol, getServiceName());
try {
mProtocol.getTransport().open();
LOG.info("Client registered with {} {} @ {}", getServiceName(), mMode, mAddress);
mConnected = true;
afterConnect();
checkVersion(getClient(), getServiceVersion());
return;
} catch (IOException e) {
if (e.getMessage() != null && FRAME_SIZE_EXCEPTION_PATTERN.matcher(e.getMessage()).find()) {
// See an error like "Frame size (67108864) larger than max length (16777216)!",
// pointing to the helper page.
String message = String.format("Failed to connect to %s %s @ %s: %s. " + "This exception may be caused by incorrect network configuration. " + "Please consult %s for common solutions to address this problem.", getServiceName(), mMode, mAddress, e.getMessage(), RuntimeConstants.ALLUXIO_DEBUG_DOCS_URL);
throw new IOException(message, e);
}
throw e;
} catch (TTransportException e) {
LOG.warn("Failed to connect ({}) to {} {} @ {}: {}", retryPolicy.getRetryCount(), getServiceName(), mMode, mAddress, e.getMessage());
if (e.getCause() instanceof java.net.SocketTimeoutException) {
// Do not retry if socket timeout.
String message = "Thrift transport open times out. Please check whether the " + "authentication types match between client and server. Note that NOSASL client " + "is not able to connect to servers with SIMPLE security mode.";
throw new IOException(message, e);
}
// TODO(peis): Consider closing the connection here as well.
if (!retryPolicy.attemptRetry()) {
break;
}
}
}
// Reaching here indicates that we did not successfully connect.
throw new ConnectionFailedException("Failed to connect to " + getServiceName() + " " + mMode + " @ " + mAddress + " after " + (retryPolicy.getRetryCount()) + " attempts");
}
Aggregations