Search in sources :

Example 6 with RetryPolicy

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;
}
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 7 with RetryPolicy

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;
}
Also used : Path(org.apache.hadoop.fs.Path) CountingRetry(alluxio.retry.CountingRetry) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy)

Example 8 with RetryPolicy

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;
}
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 9 with RetryPolicy

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());
}
Also used : UfsBlockAccessTokenUnavailableException(alluxio.exception.UfsBlockAccessTokenUnavailableException) LockBlockResource(alluxio.client.resource.LockBlockResource) TimeoutRetry(alluxio.retry.TimeoutRetry) RetryPolicy(alluxio.retry.RetryPolicy)

Example 10 with RetryPolicy

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");
}
Also used : TMultiplexedProtocol(org.apache.thrift.protocol.TMultiplexedProtocol) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) ThriftIOException(alluxio.thrift.ThriftIOException) RetryPolicy(alluxio.retry.RetryPolicy) ConnectionFailedException(alluxio.exception.ConnectionFailedException)

Aggregations

RetryPolicy (alluxio.retry.RetryPolicy)12 IOException (java.io.IOException)11 CountingRetry (alluxio.retry.CountingRetry)6 Path (org.apache.hadoop.fs.Path)6 ExponentialBackoffRetry (alluxio.retry.ExponentialBackoffRetry)4 ThriftIOException (alluxio.thrift.ThriftIOException)3 TException (org.apache.thrift.TException)3 AlluxioException (alluxio.exception.AlluxioException)2 TimeoutRetry (alluxio.retry.TimeoutRetry)2 AlluxioTException (alluxio.thrift.AlluxioTException)2 FsPermission (org.apache.hadoop.fs.permission.FsPermission)2 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)2 TMultiplexedProtocol (org.apache.thrift.protocol.TMultiplexedProtocol)2 TProtocol (org.apache.thrift.protocol.TProtocol)2 TTransportException (org.apache.thrift.transport.TTransportException)2 LockBlockResource (alluxio.client.resource.LockBlockResource)1 ConnectionFailedException (alluxio.exception.ConnectionFailedException)1 UfsBlockAccessTokenUnavailableException (alluxio.exception.UfsBlockAccessTokenUnavailableException)1 UnderFileStatus (alluxio.underfs.UnderFileStatus)1 Stack (java.util.Stack)1