Search in sources :

Example 1 with OpenSearchRejectedExecutionException

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

the class ClusterApplierService method submitStateUpdateTask.

private void submitStateUpdateTask(final String source, final ClusterStateTaskConfig config, final Function<ClusterState, ClusterState> executor, final ClusterApplyListener listener) {
    if (!lifecycle.started()) {
        return;
    }
    final ThreadContext threadContext = threadPool.getThreadContext();
    final Supplier<ThreadContext.StoredContext> supplier = threadContext.newRestorableContext(true);
    try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
        threadContext.markAsSystemContext();
        final UpdateTask updateTask = new UpdateTask(config.priority(), source, new SafeClusterApplyListener(listener, supplier, logger), executor);
        if (config.timeout() != null) {
            threadPoolExecutor.execute(updateTask, config.timeout(), () -> threadPool.generic().execute(() -> listener.onFailure(source, new ProcessClusterEventTimeoutException(config.timeout(), source))));
        } else {
            threadPoolExecutor.execute(updateTask);
        }
    } catch (OpenSearchRejectedExecutionException e) {
        // to be done here...
        if (!lifecycle.stoppedOrClosed()) {
            throw e;
        }
    }
}
Also used : ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ProcessClusterEventTimeoutException(org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)

Example 2 with OpenSearchRejectedExecutionException

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

the class MasterService method submitStateUpdateTasks.

/**
 * Submits a batch of cluster state update tasks; submitted updates are guaranteed to be processed together,
 * potentially with more tasks of the same executor.
 *
 * @param source   the source of the cluster state update task
 * @param tasks    a map of update tasks and their corresponding listeners
 * @param config   the cluster state update task configuration
 * @param executor the cluster state update task executor; tasks
 *                 that share the same executor will be executed
 *                 batches on this executor
 * @param <T>      the type of the cluster state update task state
 */
public <T> void submitStateUpdateTasks(final String source, final Map<T, ClusterStateTaskListener> tasks, final ClusterStateTaskConfig config, final ClusterStateTaskExecutor<T> executor) {
    if (!lifecycle.started()) {
        return;
    }
    final ThreadContext threadContext = threadPool.getThreadContext();
    final Supplier<ThreadContext.StoredContext> supplier = threadContext.newRestorableContext(true);
    try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
        threadContext.markAsSystemContext();
        List<Batcher.UpdateTask> safeTasks = tasks.entrySet().stream().map(e -> taskBatcher.new UpdateTask(config.priority(), source, e.getKey(), safe(e.getValue(), supplier), executor)).collect(Collectors.toList());
        taskBatcher.submitTasks(safeTasks, config.timeout());
    } catch (OpenSearchRejectedExecutionException e) {
        // to be done here...
        if (!lifecycle.stoppedOrClosed()) {
            throw e;
        }
    }
}
Also used : ClusterStateTaskListener(org.opensearch.cluster.ClusterStateTaskListener) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) AckedClusterStateTaskListener(org.opensearch.cluster.AckedClusterStateTaskListener) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) Arrays(java.util.Arrays) Metadata(org.opensearch.cluster.metadata.Metadata) CountDown(org.opensearch.common.util.concurrent.CountDown) PrioritizedOpenSearchThreadPoolExecutor(org.opensearch.common.util.concurrent.PrioritizedOpenSearchThreadPoolExecutor) ThreadPool(org.opensearch.threadpool.ThreadPool) Priority(org.opensearch.common.Priority) Node(org.opensearch.node.Node) FutureUtils(org.opensearch.common.util.concurrent.FutureUtils) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) OpenSearchExecutors(org.opensearch.common.util.concurrent.OpenSearchExecutors) Supplier(java.util.function.Supplier) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ClusterTasksResult(org.opensearch.cluster.ClusterStateTaskExecutor.ClusterTasksResult) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) Locale(java.util.Locale) OpenSearchExecutors.daemonThreadFactory(org.opensearch.common.util.concurrent.OpenSearchExecutors.daemonThreadFactory) Assertions(org.opensearch.Assertions) Map(java.util.Map) ClusterStatePublisher(org.opensearch.cluster.coordination.ClusterStatePublisher) ClusterStateTaskConfig(org.opensearch.cluster.ClusterStateTaskConfig) ClusterSettings(org.opensearch.common.settings.ClusterSettings) ProcessClusterEventTimeoutException(org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException) Setting(org.opensearch.common.settings.Setting) TimeValue(org.opensearch.common.unit.TimeValue) ClusterStateTaskExecutor(org.opensearch.cluster.ClusterStateTaskExecutor) Settings(org.opensearch.common.settings.Settings) Discovery(org.opensearch.discovery.Discovery) Collectors(java.util.stream.Collectors) Nullable(org.opensearch.common.Nullable) FailedToCommitClusterStateException(org.opensearch.cluster.coordination.FailedToCommitClusterStateException) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) AbstractLifecycleComponent(org.opensearch.common.component.AbstractLifecycleComponent) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Builder(org.opensearch.cluster.ClusterState.Builder) RoutingTable(org.opensearch.cluster.routing.RoutingTable) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) Text(org.opensearch.common.text.Text) Scheduler(org.opensearch.threadpool.Scheduler) ClusterChangedEvent(org.opensearch.cluster.ClusterChangedEvent) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)

Example 3 with OpenSearchRejectedExecutionException

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

the class AsyncShardFetch method processAsyncFetch.

/**
 * Called by the response handler of the async action to fetch data. Verifies that its still working
 * on the same cache generation, otherwise the results are discarded. It then goes and fills the relevant data for
 * the shard (response + failures), issuing a reroute at the end of it to make sure there will be another round
 * of allocations taking this new data into account.
 */
protected synchronized void processAsyncFetch(List<T> responses, List<FailedNodeException> failures, long fetchingRound) {
    if (closed) {
        // we are closed, no need to process this async fetch at all
        logger.trace("{} ignoring fetched [{}] results, already closed", shardId, type);
        return;
    }
    logger.trace("{} processing fetched [{}] results", shardId, type);
    if (responses != null) {
        for (T response : responses) {
            NodeEntry<T> nodeEntry = cache.get(response.getNode().getId());
            if (nodeEntry != null) {
                if (nodeEntry.getFetchingRound() != fetchingRound) {
                    assert nodeEntry.getFetchingRound() > fetchingRound : "node entries only replaced by newer rounds";
                    logger.trace("{} received response for [{}] from node {} for an older fetching round (expected: {} but was: {})", shardId, nodeEntry.getNodeId(), type, nodeEntry.getFetchingRound(), fetchingRound);
                } else if (nodeEntry.isFailed()) {
                    logger.trace("{} node {} has failed for [{}] (failure [{}])", shardId, nodeEntry.getNodeId(), type, nodeEntry.getFailure());
                } else {
                    // if the entry is there, for the right fetching round and not marked as failed already, process it
                    logger.trace("{} marking {} as done for [{}], result is [{}]", shardId, nodeEntry.getNodeId(), type, response);
                    nodeEntry.doneFetching(response);
                }
            }
        }
    }
    if (failures != null) {
        for (FailedNodeException failure : failures) {
            logger.trace("{} processing failure {} for [{}]", shardId, failure, type);
            NodeEntry<T> nodeEntry = cache.get(failure.nodeId());
            if (nodeEntry != null) {
                if (nodeEntry.getFetchingRound() != fetchingRound) {
                    assert nodeEntry.getFetchingRound() > fetchingRound : "node entries only replaced by newer rounds";
                    logger.trace("{} received failure for [{}] from node {} for an older fetching round (expected: {} but was: {})", shardId, nodeEntry.getNodeId(), type, nodeEntry.getFetchingRound(), fetchingRound);
                } else if (nodeEntry.isFailed() == false) {
                    // if the entry is there, for the right fetching round and not marked as failed already, process it
                    Throwable unwrappedCause = ExceptionsHelper.unwrapCause(failure.getCause());
                    // if the request got rejected or timed out, we need to try it again next time...
                    if (unwrappedCause instanceof OpenSearchRejectedExecutionException || unwrappedCause instanceof ReceiveTimeoutTransportException || unwrappedCause instanceof OpenSearchTimeoutException) {
                        nodeEntry.restartFetching();
                    } else {
                        logger.warn(() -> new ParameterizedMessage("{}: failed to list shard for {} on node [{}]", shardId, type, failure.nodeId()), failure);
                        nodeEntry.doneFetching(failure.getCause());
                    }
                }
            }
        }
    }
    reroute(shardId, "post_response");
}
Also used : ReceiveTimeoutTransportException(org.opensearch.transport.ReceiveTimeoutTransportException) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) FailedNodeException(org.opensearch.action.FailedNodeException) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Example 4 with OpenSearchRejectedExecutionException

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

the class RetryTests method blockExecutor.

/**
 * Blocks the named executor by getting its only thread running a task blocked on a CyclicBarrier and fills the queue with a noop task.
 * So requests to use this queue should get {@link OpenSearchRejectedExecutionException}s.
 */
private CyclicBarrier blockExecutor(String name, String node) throws Exception {
    ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class, node);
    CyclicBarrier barrier = new CyclicBarrier(2);
    logger.info("Blocking the [{}] executor", name);
    threadPool.executor(name).execute(() -> {
        try {
            threadPool.executor(name).execute(() -> {
            });
            barrier.await();
            logger.info("Blocked the [{}] executor", name);
            barrier.await();
            logger.info("Unblocking the [{}] executor", name);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    barrier.await();
    blockedExecutors.add(barrier);
    return barrier;
}
Also used : ThreadPool(org.opensearch.threadpool.ThreadPool) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) CyclicBarrier(java.util.concurrent.CyclicBarrier)

Example 5 with OpenSearchRejectedExecutionException

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

the class RemoteResponseParsersTests method testFailureWithoutIndex.

/**
 * Check that we can parse shard search failures without index information.
 */
public void testFailureWithoutIndex() throws IOException {
    ShardSearchFailure failure = new ShardSearchFailure(new OpenSearchRejectedExecutionException("exhausted"));
    XContentBuilder builder = jsonBuilder();
    failure.toXContent(builder, ToXContent.EMPTY_PARAMS);
    try (XContentParser parser = createParser(builder)) {
        ScrollableHitSource.SearchFailure parsed = RemoteResponseParsers.SEARCH_FAILURE_PARSER.parse(parser, null);
        assertNotNull(parsed.getReason());
        assertThat(parsed.getReason().getMessage(), Matchers.containsString("exhausted"));
        assertThat(parsed.getReason(), Matchers.instanceOf(OpenSearchRejectedExecutionException.class));
    }
}
Also used : OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure) ScrollableHitSource(org.opensearch.index.reindex.ScrollableHitSource) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

OpenSearchRejectedExecutionException (org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)33 OpenSearchException (org.opensearch.OpenSearchException)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 IOException (java.io.IOException)7 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)7 ActionListener (org.opensearch.action.ActionListener)7 TimeValue (org.opensearch.common.unit.TimeValue)6 ShardId (org.opensearch.index.shard.ShardId)6 List (java.util.List)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Nullable (org.opensearch.common.Nullable)4 AbstractRunnable (org.opensearch.common.util.concurrent.AbstractRunnable)4 ExecutionException (java.util.concurrent.ExecutionException)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)3 SearchResponse (org.opensearch.action.search.SearchResponse)3 Releasable (org.opensearch.common.lease.Releasable)3 EOFException (java.io.EOFException)2 FileNotFoundException (java.io.FileNotFoundException)2 AccessDeniedException (java.nio.file.AccessDeniedException)2 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)2