Search in sources :

Example 1 with RetryPolicy

use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.

the class ThriftClientPool method createNewResource.

/**
   * Creates a thrift client instance.
   *
   * @return the thrift client created
   * @throws IOException if it fails to create a thrift client
   */
@Override
protected T createNewResource() throws IOException {
    TTransport transport = mTransportProvider.getClientTransport(mParentSubject, mAddress);
    TProtocol binaryProtocol = new TBinaryProtocol(transport);
    T client = createThriftClient(new TMultiplexedProtocol(binaryProtocol, mServiceName));
    TException exception;
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
    do {
        LOG.info("Alluxio client (version {}) is trying to connect with {} {} @ {}", RuntimeConstants.VERSION, mServiceName, mAddress);
        try {
            if (!transport.isOpen()) {
                transport.open();
            }
            if (transport.isOpen()) {
                checkVersion(client);
            }
            LOG.info("Client registered with {} @ {}", mServiceName, mAddress);
            return client;
        } catch (TTransportException e) {
            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);
            }
            LOG.warn("Failed to connect ({}) to {} @ {}: {}", retryPolicy.getRetryCount(), mServiceName, mAddress, e.getMessage());
            exception = e;
        }
    } while (retryPolicy.attemptRetry());
    LOG.error("Failed after " + retryPolicy.getRetryCount() + " retries.");
    Preconditions.checkNotNull(exception);
    throw new IOException(exception);
}
Also used : TException(org.apache.thrift.TException) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) TMultiplexedProtocol(org.apache.thrift.protocol.TMultiplexedProtocol) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) RetryPolicy(alluxio.retry.RetryPolicy)

Example 2 with RetryPolicy

use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.

the class AbstractMaster method waitForJournalFlush.

/**
   * Waits for the flush counter to be flushed to the journal. If the counter is
   * {@link #INVALID_FLUSH_COUNTER}, this is a noop.
   *
   * @param journalContext the journal context
   */
private void waitForJournalFlush(JournalContext journalContext) {
    if (journalContext.getFlushCounter() == INVALID_FLUSH_COUNTER) {
        // Check this before the precondition.
        return;
    }
    Preconditions.checkNotNull(mAsyncJournalWriter, PreconditionMessage.ASYNC_JOURNAL_WRITER_NULL);
    RetryPolicy retry = new TimeoutRetry(JOURNAL_FLUSH_RETRY_TIMEOUT_MS, Constants.SECOND_MS);
    int attempts = 0;
    while (retry.attemptRetry()) {
        try {
            attempts++;
            mAsyncJournalWriter.flush(journalContext.getFlushCounter());
            return;
        } catch (IOException e) {
            LOG.warn("Journal flush failed. retrying...", e);
        }
    }
    LOG.error("Journal flush failed after {} attempts. Terminating process to prevent inconsistency.", attempts);
    if (Configuration.getBoolean(PropertyKey.TEST_MODE)) {
        throw new RuntimeException("Journal flush failed after " + attempts + " attempts. Terminating process to prevent inconsistency.");
    }
    System.exit(-1);
}
Also used : TimeoutRetry(alluxio.retry.TimeoutRetry) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy)

Example 3 with RetryPolicy

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

Example 4 with RetryPolicy

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

Example 5 with RetryPolicy

use of alluxio.retry.RetryPolicy 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;
}
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)

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