use of alluxio.retry.CountingRetry 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.CountingRetry in project alluxio by Alluxio.
the class RetryHandlingFileSystemWorkerClient method init.
private void init() throws IOException {
// Register the session before any RPCs for this session start.
ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
try {
sessionHeartbeat(retryPolicy);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// The heartbeat is scheduled to run in a fixed rate. The heartbeat won't consume a thread
// from the pool while it is not running.
mHeartbeat = HEARTBEAT_POOL.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
sessionHeartbeat(new CountingRetry(0));
} catch (InterruptedException e) {
// do nothing
} catch (Exception e) {
LOG.warn("Failed to heartbeat for session {}", mSessionId, e.getMessage());
}
}
}, Configuration.getInt(PropertyKey.USER_HEARTBEAT_INTERVAL_MS), Configuration.getInt(PropertyKey.USER_HEARTBEAT_INTERVAL_MS), TimeUnit.MILLISECONDS);
NUM_ACTIVE_SESSIONS.incrementAndGet();
}
use of alluxio.retry.CountingRetry in project alluxio by Alluxio.
the class RetryHandlingBlockWorkerClient method init.
private void init() throws IOException {
if (mSessionId != null) {
// Register the session before any RPCs for this session start.
ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
try {
sessionHeartbeat(retryPolicy);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// The heartbeat is scheduled to run in a fixed rate. The heartbeat won't consume a thread
// from the pool while it is not running.
mHeartbeat = HEARTBEAT_POOL.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
sessionHeartbeat(new CountingRetry(0));
} catch (InterruptedException e) {
// Do nothing.
} catch (Exception e) {
LOG.warn("Failed to heartbeat for session {}", mSessionId, e.getMessage());
}
}
}, Configuration.getInt(PropertyKey.USER_HEARTBEAT_INTERVAL_MS), Configuration.getInt(PropertyKey.USER_HEARTBEAT_INTERVAL_MS), TimeUnit.MILLISECONDS);
NUM_ACTIVE_SESSIONS.incrementAndGet();
}
}
Aggregations