Search in sources :

Example 1 with RetryableAction

use of org.elasticsearch.action.support.RetryableAction in project crate by crate.

the class RemoteRecoveryTargetHandler method executeRetryableAction.

private <T extends TransportResponse> void executeRetryableAction(String action, TransportRequest request, TransportRequestOptions options, ActionListener<T> actionListener, Writeable.Reader<T> reader) {
    final Object key = new Object();
    final ActionListener<T> removeListener = ActionListener.runBefore(actionListener, () -> onGoingRetryableActions.remove(key));
    final TimeValue initialDelay = TimeValue.timeValueMillis(200);
    final TimeValue timeout = recoverySettings.internalActionRetryTimeout();
    final RetryableAction<T> retryableAction = new RetryableAction<T>(LOGGER, threadPool, initialDelay, timeout, removeListener) {

        @Override
        public void tryAction(ActionListener<T> listener) {
            transportService.sendRequest(targetNode, action, request, options, new ActionListenerResponseHandler<>(listener, reader, ThreadPool.Names.GENERIC));
        }

        @Override
        public boolean shouldRetry(Exception e) {
            return retryableException(e);
        }
    };
    onGoingRetryableActions.put(key, retryableAction);
    retryableAction.run();
    if (isCancelled) {
        retryableAction.cancel(new CancellableThreads.ExecutionCancelledException("recovery was cancelled"));
    }
}
Also used : RetryableAction(org.elasticsearch.action.support.RetryableAction) CancellableThreads(org.elasticsearch.common.util.CancellableThreads) ActionListener(org.elasticsearch.action.ActionListener) TimeValue(io.crate.common.unit.TimeValue) ElasticsearchException(org.elasticsearch.ElasticsearchException) IOException(java.io.IOException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Aggregations

TimeValue (io.crate.common.unit.TimeValue)1 IOException (java.io.IOException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ActionListener (org.elasticsearch.action.ActionListener)1 RetryableAction (org.elasticsearch.action.support.RetryableAction)1 CircuitBreakingException (org.elasticsearch.common.breaker.CircuitBreakingException)1 CancellableThreads (org.elasticsearch.common.util.CancellableThreads)1 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)1 RemoteTransportException (org.elasticsearch.transport.RemoteTransportException)1