Search in sources :

Example 1 with ProcessClusterEventTimeoutException

use of org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException 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 ProcessClusterEventTimeoutException

use of org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException in project OpenSearch by opensearch-project.

the class TaskExecutorTests method submitTask.

// can be overridden by TaskBatcherTests
protected void submitTask(String source, TestTask testTask) {
    SourcePrioritizedRunnable task = new UpdateTask(source, testTask);
    TimeValue timeout = testTask.timeout();
    if (timeout != null) {
        threadExecutor.execute(task, timeout, () -> threadPool.generic().execute(() -> {
            logger.debug("task [{}] timed out after [{}]", task, timeout);
            testTask.onFailure(source, new ProcessClusterEventTimeoutException(timeout, source));
        }));
    } else {
        threadExecutor.execute(task);
    }
}
Also used : ProcessClusterEventTimeoutException(org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException) TimeValue(org.opensearch.common.unit.TimeValue)

Example 3 with ProcessClusterEventTimeoutException

use of org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException in project OpenSearch by opensearch-project.

the class TransportClusterHealthAction method waitForEventsAndExecuteHealth.

private void waitForEventsAndExecuteHealth(final ClusterHealthRequest request, final ActionListener<ClusterHealthResponse> listener, final int waitCount, final long endTimeRelativeMillis) {
    assert request.waitForEvents() != null;
    if (request.local()) {
        clusterService.submitStateUpdateTask("cluster_health (wait_for_events [" + request.waitForEvents() + "])", new LocalClusterUpdateTask(request.waitForEvents()) {

            @Override
            public ClusterTasksResult<LocalClusterUpdateTask> execute(ClusterState currentState) {
                return unchanged();
            }

            @Override
            public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
                final long timeoutInMillis = Math.max(0, endTimeRelativeMillis - threadPool.relativeTimeInMillis());
                final TimeValue newTimeout = TimeValue.timeValueMillis(timeoutInMillis);
                request.timeout(newTimeout);
                executeHealth(request, clusterService.state(), listener, waitCount, observedState -> waitForEventsAndExecuteHealth(request, listener, waitCount, endTimeRelativeMillis));
            }

            @Override
            public void onFailure(String source, Exception e) {
                logger.error(() -> new ParameterizedMessage("unexpected failure during [{}]", source), e);
                listener.onFailure(e);
            }
        });
    } else {
        final TimeValue taskTimeout = TimeValue.timeValueMillis(Math.max(0, endTimeRelativeMillis - threadPool.relativeTimeInMillis()));
        clusterService.submitStateUpdateTask("cluster_health (wait_for_events [" + request.waitForEvents() + "])", new ClusterStateUpdateTask(request.waitForEvents()) {

            @Override
            public ClusterState execute(ClusterState currentState) {
                return currentState;
            }

            @Override
            public TimeValue timeout() {
                return taskTimeout;
            }

            @Override
            public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
                final long timeoutInMillis = Math.max(0, endTimeRelativeMillis - threadPool.relativeTimeInMillis());
                final TimeValue newTimeout = TimeValue.timeValueMillis(timeoutInMillis);
                request.timeout(newTimeout);
                // we must use the state from the applier service, because if the state-not-recovered block is in place then the
                // applier service has a different view of the cluster state from the one supplied here
                final ClusterState appliedState = clusterService.state();
                assert newState.stateUUID().equals(appliedState.stateUUID()) : newState.stateUUID() + " vs " + appliedState.stateUUID();
                executeHealth(request, appliedState, listener, waitCount, observedState -> waitForEventsAndExecuteHealth(request, listener, waitCount, endTimeRelativeMillis));
            }

            @Override
            public void onNoLongerMaster(String source) {
                logger.trace("stopped being master while waiting for events with priority [{}]. retrying.", request.waitForEvents());
                // TransportMasterNodeAction implements the retry logic, which is triggered by passing a NotMasterException
                listener.onFailure(new NotMasterException("no longer master. source: [" + source + "]"));
            }

            @Override
            public void onFailure(String source, Exception e) {
                if (e instanceof ProcessClusterEventTimeoutException) {
                    listener.onResponse(getResponse(request, clusterService.state(), waitCount, TimeoutState.TIMED_OUT));
                } else {
                    logger.error(() -> new ParameterizedMessage("unexpected failure during [{}]", source), e);
                    listener.onFailure(e);
                }
            }
        });
    }
}
Also used : ThreadPool(org.opensearch.threadpool.ThreadPool) AllocationService(org.opensearch.cluster.routing.allocation.AllocationService) IndicesOptions(org.opensearch.action.support.IndicesOptions) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Strings(org.opensearch.common.Strings) ClusterState(org.opensearch.cluster.ClusterState) NotMasterException(org.opensearch.cluster.NotMasterException) NodeClosedException(org.opensearch.node.NodeClosedException) Inject(org.opensearch.common.inject.Inject) ActionListener(org.opensearch.action.ActionListener) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) ClusterHealthStatus(org.opensearch.cluster.health.ClusterHealthStatus) ProcessClusterEventTimeoutException(org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException) StreamInput(org.opensearch.common.io.stream.StreamInput) TimeValue(org.opensearch.common.unit.TimeValue) CollectionUtils(org.opensearch.common.util.CollectionUtils) Predicate(java.util.function.Predicate) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) Task(org.opensearch.tasks.Task) TransportService(org.opensearch.transport.TransportService) ActiveShardCount(org.opensearch.action.support.ActiveShardCount) LocalClusterUpdateTask(org.opensearch.cluster.LocalClusterUpdateTask) Consumer(java.util.function.Consumer) ActionFilters(org.opensearch.action.support.ActionFilters) Logger(org.apache.logging.log4j.Logger) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) ClusterService(org.opensearch.cluster.service.ClusterService) LogManager(org.apache.logging.log4j.LogManager) TransportMasterNodeReadAction(org.opensearch.action.support.master.TransportMasterNodeReadAction) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) ClusterState(org.opensearch.cluster.ClusterState) LocalClusterUpdateTask(org.opensearch.cluster.LocalClusterUpdateTask) ProcessClusterEventTimeoutException(org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) NotMasterException(org.opensearch.cluster.NotMasterException) TimeValue(org.opensearch.common.unit.TimeValue) NotMasterException(org.opensearch.cluster.NotMasterException) NodeClosedException(org.opensearch.node.NodeClosedException) ProcessClusterEventTimeoutException(org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) IOException(java.io.IOException)

Aggregations

ProcessClusterEventTimeoutException (org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException)3 TimeValue (org.opensearch.common.unit.TimeValue)2 IOException (java.io.IOException)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 ActionListener (org.opensearch.action.ActionListener)1 ActionFilters (org.opensearch.action.support.ActionFilters)1 ActiveShardCount (org.opensearch.action.support.ActiveShardCount)1 IndicesOptions (org.opensearch.action.support.IndicesOptions)1 TransportMasterNodeReadAction (org.opensearch.action.support.master.TransportMasterNodeReadAction)1 ClusterState (org.opensearch.cluster.ClusterState)1 ClusterStateObserver (org.opensearch.cluster.ClusterStateObserver)1 ClusterStateUpdateTask (org.opensearch.cluster.ClusterStateUpdateTask)1 LocalClusterUpdateTask (org.opensearch.cluster.LocalClusterUpdateTask)1 NotMasterException (org.opensearch.cluster.NotMasterException)1 ClusterBlockException (org.opensearch.cluster.block.ClusterBlockException)1 ClusterHealthStatus (org.opensearch.cluster.health.ClusterHealthStatus)1