Search in sources :

Example 6 with CountingRetry

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;
}
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) Stack(java.util.Stack)

Example 7 with CountingRetry

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();
}
Also used : CountingRetry(alluxio.retry.CountingRetry) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) ThriftIOException(alluxio.thrift.ThriftIOException) AlluxioTException(alluxio.thrift.AlluxioTException) TException(org.apache.thrift.TException) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException)

Example 8 with CountingRetry

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();
    }
}
Also used : CountingRetry(alluxio.retry.CountingRetry) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) ThriftIOException(alluxio.thrift.ThriftIOException) AlluxioTException(alluxio.thrift.AlluxioTException) UfsBlockAccessTokenUnavailableException(alluxio.exception.UfsBlockAccessTokenUnavailableException) WorkerOutOfSpaceException(alluxio.exception.WorkerOutOfSpaceException) TException(org.apache.thrift.TException) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException)

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