Search in sources :

Example 1 with ExponentialBackoffRetry

use of alluxio.retry.ExponentialBackoffRetry 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 ExponentialBackoffRetry

use of alluxio.retry.ExponentialBackoffRetry 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 3 with ExponentialBackoffRetry

use of alluxio.retry.ExponentialBackoffRetry 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)

Example 4 with ExponentialBackoffRetry

use of alluxio.retry.ExponentialBackoffRetry 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)

Example 5 with ExponentialBackoffRetry

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

the class AbstractThriftClient method retryRPC.

/**
   * Similar to {@link #retryRPC(RpcCallable)} except that the RPC call may throw
   * {@link AlluxioTException} and once it is thrown, it will be transformed into
   * {@link AlluxioException} and be thrown.
   *
   * @param rpc the RPC call to be executed
   * @param <V> type of return value of the RPC call
   * @return the return value of the RPC call
   * @throws AlluxioException when {@link AlluxioTException} is thrown by the RPC call
   * @throws IOException when retries exceeds {@link #RPC_MAX_NUM_RETRY} or some server
   *         side IOException occurred.
   */
protected <V> V retryRPC(RpcCallableThrowsAlluxioTException<V, C> rpc) throws AlluxioException, IOException {
    TException exception = null;
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
    do {
        C client = acquireClient();
        try {
            return rpc.call(client);
        } catch (AlluxioTException e) {
            AlluxioException ae = AlluxioException.fromThrift(e);
            processException(client, ae);
            exception = new TException(ae);
        } catch (ThriftIOException e) {
            throw new IOException(e);
        } catch (TException e) {
            LOG.error(e.getMessage(), e);
            closeClient(client);
            exception = e;
        } finally {
            releaseClient(client);
        }
    } while (retryPolicy.attemptRetry());
    LOG.error("Failed after " + retryPolicy.getRetryCount() + " retries.");
    Preconditions.checkNotNull(exception);
    throw new IOException(exception);
}
Also used : AlluxioTException(alluxio.thrift.AlluxioTException) TException(org.apache.thrift.TException) AlluxioTException(alluxio.thrift.AlluxioTException) ThriftIOException(alluxio.thrift.ThriftIOException) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) ThriftIOException(alluxio.thrift.ThriftIOException) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy) AlluxioException(alluxio.exception.AlluxioException)

Aggregations

ExponentialBackoffRetry (alluxio.retry.ExponentialBackoffRetry)6 IOException (java.io.IOException)6 ThriftIOException (alluxio.thrift.ThriftIOException)5 TException (org.apache.thrift.TException)5 AlluxioException (alluxio.exception.AlluxioException)4 RetryPolicy (alluxio.retry.RetryPolicy)4 AlluxioTException (alluxio.thrift.AlluxioTException)4 CountingRetry (alluxio.retry.CountingRetry)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 ConnectionFailedException (alluxio.exception.ConnectionFailedException)1 UfsBlockAccessTokenUnavailableException (alluxio.exception.UfsBlockAccessTokenUnavailableException)1 WorkerOutOfSpaceException (alluxio.exception.WorkerOutOfSpaceException)1 TTransport (org.apache.thrift.transport.TTransport)1