Search in sources :

Example 31 with OpenSearchRejectedExecutionException

use of org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException in project OpenSearch by opensearch-project.

the class ShardIndexingPressure method rejectShardRequest.

private void rejectShardRequest(ShardIndexingPressureTracker tracker, long bytes, long nodeTotalBytes, long shardTotalBytes, RejectionTracker rejectionTracker, String operationType) {
    long nodeBytesWithoutOperation = nodeTotalBytes - bytes;
    long shardBytesWithoutOperation = shardTotalBytes - bytes;
    ShardId shardId = tracker.getShardId();
    rejectionTracker.incrementTotalRejections();
    throw new OpenSearchRejectedExecutionException("rejected execution of " + operationType + " operation [" + "shard_detail=[" + shardId.getIndexName() + "][" + shardId.id() + "], " + "shard_total_bytes=" + shardBytesWithoutOperation + ", " + "shard_operation_bytes=" + bytes + ", " + "shard_max_coordinating_and_primary_bytes=" + tracker.getPrimaryAndCoordinatingLimits() + ", " + "shard_max_replica_bytes=" + tracker.getReplicaLimits() + "] OR [" + "node_total_bytes=" + nodeBytesWithoutOperation + ", " + "node_operation_bytes=" + bytes + ", " + "node_max_coordinating_and_primary_bytes=" + primaryAndCoordinatingLimits + ", " + "node_max_replica_bytes=" + replicaLimits + "]", false);
}
Also used : ShardId(org.opensearch.index.shard.ShardId) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)

Example 32 with OpenSearchRejectedExecutionException

use of org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException in project OpenSearch by opensearch-project.

the class RetryableActionTests method testRetryableActionWillRetry.

public void testRetryableActionWillRetry() {
    int expectedRetryCount = randomIntBetween(1, 8);
    final AtomicInteger remainingFailedCount = new AtomicInteger(expectedRetryCount);
    final AtomicInteger retryCount = new AtomicInteger();
    final PlainActionFuture<Boolean> future = PlainActionFuture.newFuture();
    final RetryableAction<Boolean> retryableAction = new RetryableAction<Boolean>(logger, taskQueue.getThreadPool(), TimeValue.timeValueMillis(10), TimeValue.timeValueSeconds(30), future) {

        @Override
        public void tryAction(ActionListener<Boolean> listener) {
            if (remainingFailedCount.getAndDecrement() == 0) {
                listener.onResponse(true);
            } else {
                if (randomBoolean()) {
                    listener.onFailure(new OpenSearchRejectedExecutionException());
                } else {
                    throw new OpenSearchRejectedExecutionException();
                }
            }
        }

        @Override
        public boolean shouldRetry(Exception e) {
            retryCount.getAndIncrement();
            return e instanceof OpenSearchRejectedExecutionException;
        }
    };
    retryableAction.run();
    taskQueue.runAllRunnableTasks();
    long previousDeferredTime = 0;
    for (int i = 0; i < expectedRetryCount; ++i) {
        assertTrue(taskQueue.hasDeferredTasks());
        final long deferredExecutionTime = taskQueue.getLatestDeferredExecutionTime();
        final long millisBound = 10 << i;
        assertThat(deferredExecutionTime, lessThanOrEqualTo(millisBound + previousDeferredTime));
        previousDeferredTime = deferredExecutionTime;
        taskQueue.advanceTime();
        taskQueue.runAllRunnableTasks();
    }
    assertEquals(expectedRetryCount, retryCount.get());
    assertTrue(future.actionGet());
}
Also used : ActionListener(org.opensearch.action.ActionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) OpenSearchException(org.opensearch.OpenSearchException)

Example 33 with OpenSearchRejectedExecutionException

use of org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException in project OpenSearch by opensearch-project.

the class RetryableActionTests method testRetryableActionTimeout.

public void testRetryableActionTimeout() {
    final AtomicInteger retryCount = new AtomicInteger();
    final PlainActionFuture<Boolean> future = PlainActionFuture.newFuture();
    final RetryableAction<Boolean> retryableAction = new RetryableAction<Boolean>(logger, taskQueue.getThreadPool(), TimeValue.timeValueMillis(10), TimeValue.timeValueSeconds(1), future) {

        @Override
        public void tryAction(ActionListener<Boolean> listener) {
            if (randomBoolean()) {
                listener.onFailure(new OpenSearchRejectedExecutionException());
            } else {
                throw new OpenSearchRejectedExecutionException();
            }
        }

        @Override
        public boolean shouldRetry(Exception e) {
            retryCount.getAndIncrement();
            return e instanceof OpenSearchRejectedExecutionException;
        }
    };
    retryableAction.run();
    taskQueue.runAllRunnableTasks();
    long previousDeferredTime = 0;
    while (previousDeferredTime < 1000) {
        assertTrue(taskQueue.hasDeferredTasks());
        previousDeferredTime = taskQueue.getLatestDeferredExecutionTime();
        taskQueue.advanceTime();
        taskQueue.runAllRunnableTasks();
    }
    assertFalse(taskQueue.hasDeferredTasks());
    assertFalse(taskQueue.hasRunnableTasks());
    expectThrows(OpenSearchRejectedExecutionException.class, future::actionGet);
}
Also used : ActionListener(org.opensearch.action.ActionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) OpenSearchException(org.opensearch.OpenSearchException)

Example 34 with OpenSearchRejectedExecutionException

use of org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException in project OpenSearch by opensearch-project.

the class RetryableActionTests method testRetryableActionCancelled.

public void testRetryableActionCancelled() {
    final AtomicInteger executedCount = new AtomicInteger();
    final PlainActionFuture<Boolean> future = PlainActionFuture.newFuture();
    final RetryableAction<Boolean> retryableAction = new RetryableAction<Boolean>(logger, taskQueue.getThreadPool(), TimeValue.timeValueMillis(10), TimeValue.timeValueSeconds(30), future) {

        @Override
        public void tryAction(ActionListener<Boolean> listener) {
            if (executedCount.incrementAndGet() == 1) {
                throw new OpenSearchRejectedExecutionException();
            } else {
                listener.onResponse(true);
            }
        }

        @Override
        public boolean shouldRetry(Exception e) {
            return e instanceof OpenSearchRejectedExecutionException;
        }
    };
    retryableAction.run();
    taskQueue.runAllRunnableTasks();
    assertTrue(taskQueue.hasDeferredTasks());
    taskQueue.advanceTime();
    retryableAction.cancel(new OpenSearchException("Cancelled"));
    taskQueue.runAllRunnableTasks();
    // A second run will not occur because it is cancelled
    assertEquals(1, executedCount.get());
    expectThrows(OpenSearchException.class, future::actionGet);
}
Also used : ActionListener(org.opensearch.action.ActionListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) OpenSearchException(org.opensearch.OpenSearchException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) OpenSearchException(org.opensearch.OpenSearchException)

Example 35 with OpenSearchRejectedExecutionException

use of org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException in project OpenSearch by opensearch-project.

the class RemoteConnectionStrategy method connect.

/**
 * Triggers a connect round unless there is one running already. If there is a connect round running, the listener will either
 * be queued or rejected and failed.
 */
void connect(ActionListener<Void> connectListener) {
    boolean runConnect = false;
    final ActionListener<Void> listener = ContextPreservingActionListener.wrapPreservingContext(connectListener, transportService.getThreadPool().getThreadContext());
    boolean closed;
    synchronized (mutex) {
        closed = this.closed.get();
        if (closed) {
            assert listeners.isEmpty();
        } else {
            if (listeners.size() >= maxPendingConnectionListeners) {
                assert listeners.size() == maxPendingConnectionListeners;
                listener.onFailure(new OpenSearchRejectedExecutionException("connect listener queue is full"));
                return;
            } else {
                listeners.add(listener);
            }
            runConnect = listeners.size() == 1;
        }
    }
    if (closed) {
        connectListener.onFailure(new AlreadyClosedException("connect handler is already closed"));
        return;
    }
    if (runConnect) {
        ExecutorService executor = transportService.getThreadPool().executor(ThreadPool.Names.MANAGEMENT);
        executor.submit(new AbstractRunnable() {

            @Override
            public void onFailure(Exception e) {
                ActionListener.onFailure(getAndClearListeners(), e);
            }

            @Override
            protected void doRun() {
                connectImpl(new ActionListener<Void>() {

                    @Override
                    public void onResponse(Void aVoid) {
                        ActionListener.onResponse(getAndClearListeners(), aVoid);
                    }

                    @Override
                    public void onFailure(Exception e) {
                        ActionListener.onFailure(getAndClearListeners(), e);
                    }
                });
            }
        });
    }
}
Also used : AbstractRunnable(org.opensearch.common.util.concurrent.AbstractRunnable) ContextPreservingActionListener(org.opensearch.action.support.ContextPreservingActionListener) ActionListener(org.opensearch.action.ActionListener) ExecutorService(java.util.concurrent.ExecutorService) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) UnknownHostException(java.net.UnknownHostException)

Aggregations

OpenSearchRejectedExecutionException (org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)43 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 OpenSearchException (org.opensearch.OpenSearchException)11 ActionListener (org.opensearch.action.ActionListener)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 IOException (java.io.IOException)7 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)7 TimeValue (org.opensearch.common.unit.TimeValue)7 ShardId (org.opensearch.index.shard.ShardId)6 SearchResponse (org.opensearch.action.search.SearchResponse)5 List (java.util.List)4 SearchPhaseExecutionException (org.opensearch.action.search.SearchPhaseExecutionException)4 Nullable (org.opensearch.common.Nullable)4 AbstractRunnable (org.opensearch.common.util.concurrent.AbstractRunnable)4 ThreadPool (org.opensearch.threadpool.ThreadPool)4 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)3 ShardSearchFailure (org.opensearch.action.search.ShardSearchFailure)3 Releasable (org.opensearch.common.lease.Releasable)3