Search in sources :

Example 1 with RetryableAction

use of org.opensearch.action.support.RetryableAction in project OpenSearch by opensearch-project.

the class ReplicationOperation method performOnReplica.

private void performOnReplica(final ShardRouting shard, final ReplicaRequest replicaRequest, final long globalCheckpoint, final long maxSeqNoOfUpdatesOrDeletes, final PendingReplicationActions pendingReplicationActions) {
    if (logger.isTraceEnabled()) {
        logger.trace("[{}] sending op [{}] to replica {} for request [{}]", shard.shardId(), opType, shard, replicaRequest);
    }
    totalShards.incrementAndGet();
    pendingActions.incrementAndGet();
    final ActionListener<ReplicaResponse> replicationListener = new ActionListener<ReplicaResponse>() {

        @Override
        public void onResponse(ReplicaResponse response) {
            successfulShards.incrementAndGet();
            try {
                updateCheckPoints(shard, response::localCheckpoint, response::globalCheckpoint);
            } finally {
                decPendingAndFinishIfNeeded();
            }
        }

        @Override
        public void onFailure(Exception replicaException) {
            logger.trace(() -> new ParameterizedMessage("[{}] failure while performing [{}] on replica {}, request [{}]", shard.shardId(), opType, shard, replicaRequest), replicaException);
            // Only report "critical" exceptions - TODO: Reach out to the master node to get the latest shard state then report.
            if (TransportActions.isShardNotAvailableException(replicaException) == false) {
                RestStatus restStatus = ExceptionsHelper.status(replicaException);
                shardReplicaFailures.add(new ReplicationResponse.ShardInfo.Failure(shard.shardId(), shard.currentNodeId(), replicaException, restStatus, false));
            }
            String message = String.format(Locale.ROOT, "failed to perform %s on replica %s", opType, shard);
            replicasProxy.failShardIfNeeded(shard, primaryTerm, message, replicaException, ActionListener.wrap(r -> decPendingAndFinishIfNeeded(), ReplicationOperation.this::onNoLongerPrimary));
        }

        @Override
        public String toString() {
            return "[" + replicaRequest + "][" + shard + "]";
        }
    };
    final String allocationId = shard.allocationId().getId();
    final RetryableAction<ReplicaResponse> replicationAction = new RetryableAction<ReplicaResponse>(logger, threadPool, initialRetryBackoffBound, retryTimeout, replicationListener) {

        @Override
        public void tryAction(ActionListener<ReplicaResponse> listener) {
            replicasProxy.performOn(shard, replicaRequest, primaryTerm, globalCheckpoint, maxSeqNoOfUpdatesOrDeletes, listener);
        }

        @Override
        public void onFinished() {
            super.onFinished();
            pendingReplicationActions.removeReplicationAction(allocationId, this);
        }

        @Override
        public boolean shouldRetry(Exception e) {
            final Throwable cause = ExceptionsHelper.unwrapCause(e);
            return cause instanceof CircuitBreakingException || cause instanceof OpenSearchRejectedExecutionException || cause instanceof ConnectTransportException;
        }
    };
    pendingReplicationActions.addPendingAction(allocationId, replicationAction);
    replicationAction.run();
}
Also used : OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) SequenceNumbers(org.opensearch.index.seqno.SequenceNumbers) LongSupplier(java.util.function.LongSupplier) ThreadPool(org.opensearch.threadpool.ThreadPool) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OpenSearchException(org.opensearch.OpenSearchException) RetryableAction(org.opensearch.action.support.RetryableAction) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Assertions(org.opensearch.Assertions) NodeClosedException(org.opensearch.node.NodeClosedException) ActionListener(org.opensearch.action.ActionListener) UnavailableShardsException(org.opensearch.action.UnavailableShardsException) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) IndexShardRoutingTable(org.opensearch.cluster.routing.IndexShardRoutingTable) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) StreamInput(org.opensearch.common.io.stream.StreamInput) TimeValue(org.opensearch.common.unit.TimeValue) ExceptionsHelper(org.opensearch.ExceptionsHelper) IOException(java.io.IOException) RestStatus(org.opensearch.rest.RestStatus) Nullable(org.opensearch.common.Nullable) ActiveShardCount(org.opensearch.action.support.ActiveShardCount) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TransportActions(org.opensearch.action.support.TransportActions) ConnectTransportException(org.opensearch.transport.ConnectTransportException) ReplicationGroup(org.opensearch.index.shard.ReplicationGroup) Collections(java.util.Collections) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) OpenSearchException(org.opensearch.OpenSearchException) NodeClosedException(org.opensearch.node.NodeClosedException) UnavailableShardsException(org.opensearch.action.UnavailableShardsException) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) IOException(java.io.IOException) ConnectTransportException(org.opensearch.transport.ConnectTransportException) RetryableAction(org.opensearch.action.support.RetryableAction) ActionListener(org.opensearch.action.ActionListener) RestStatus(org.opensearch.rest.RestStatus) ConnectTransportException(org.opensearch.transport.ConnectTransportException) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Example 2 with RetryableAction

use of org.opensearch.action.support.RetryableAction in project OpenSearch by opensearch-project.

the class RemoteRecoveryTargetHandler method executeRetryableAction.

private <T extends TransportResponse> void executeRetryableAction(String action, RecoveryTransportRequest 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 retriesSupported && retryableException(e);
        }
    };
    onGoingRetryableActions.put(key, retryableAction);
    retryableAction.run();
    if (isCancelled) {
        retryableAction.cancel(new CancellableThreads.ExecutionCancelledException("recovery was cancelled"));
    }
}
Also used : RetryableAction(org.opensearch.action.support.RetryableAction) CancellableThreads(org.opensearch.common.util.CancellableThreads) ActionListener(org.opensearch.action.ActionListener) TimeValue(org.opensearch.common.unit.TimeValue) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) OpenSearchException(org.opensearch.OpenSearchException) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) RemoteTransportException(org.opensearch.transport.RemoteTransportException) IOException(java.io.IOException) SendRequestTransportException(org.opensearch.transport.SendRequestTransportException) ConnectTransportException(org.opensearch.transport.ConnectTransportException)

Aggregations

IOException (java.io.IOException)2 OpenSearchException (org.opensearch.OpenSearchException)2 ActionListener (org.opensearch.action.ActionListener)2 RetryableAction (org.opensearch.action.support.RetryableAction)2 CircuitBreakingException (org.opensearch.common.breaker.CircuitBreakingException)2 TimeValue (org.opensearch.common.unit.TimeValue)2 OpenSearchRejectedExecutionException (org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)2 ConnectTransportException (org.opensearch.transport.ConnectTransportException)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 LongSupplier (java.util.function.LongSupplier)1 Logger (org.apache.logging.log4j.Logger)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)1 Assertions (org.opensearch.Assertions)1 ExceptionsHelper (org.opensearch.ExceptionsHelper)1