use of alluxio.retry.RetryPolicy 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);
}
use of alluxio.retry.RetryPolicy in project alluxio by Alluxio.
the class AbstractThriftClient method retryRPC.
/**
* Tries to execute an RPC defined as a {@link RpcCallable}.
*
* @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 IOException when retries exceeds {@link #RPC_MAX_NUM_RETRY} or some server
* side IOException occurred.
*/
protected <V> V retryRPC(RpcCallable<V, C> rpc) throws IOException {
TException exception;
RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
do {
C client = acquireClient();
try {
return rpc.call(client);
} catch (ThriftIOException e) {
throw new IOException(e);
} catch (AlluxioTException e) {
AlluxioException ae = AlluxioException.fromThrift(e);
try {
processException(client, ae);
} catch (AlluxioException ee) {
throw new IOException(ee);
}
exception = new TException(ae);
} catch (TException e) {
LOG.warn(e.getMessage());
closeClient(client);
exception = e;
} finally {
releaseClient(client);
}
} while (retryPolicy.attemptRetry());
LOG.error("Failed after " + retryPolicy.getRetryCount() + " retries.");
Preconditions.checkNotNull(exception);
throw new IOException(exception);
}
Aggregations