Search in sources :

Example 1 with OpenSearchTimeoutException

use of org.opensearch.OpenSearchTimeoutException in project OpenSearch by opensearch-project.

the class TransportClearVotingConfigExclusionsAction method masterOperation.

@Override
protected void masterOperation(ClearVotingConfigExclusionsRequest request, ClusterState initialState, ActionListener<ClearVotingConfigExclusionsResponse> listener) throws Exception {
    final long startTimeMillis = threadPool.relativeTimeInMillis();
    final Predicate<ClusterState> allExclusionsRemoved = newState -> {
        for (VotingConfigExclusion tombstone : initialState.getVotingConfigExclusions()) {
            // NB checking for the existence of any node with this persistent ID, because persistent IDs are how votes are counted.
            if (newState.nodes().nodeExists(tombstone.getNodeId())) {
                return false;
            }
        }
        return true;
    };
    if (request.getWaitForRemoval() && allExclusionsRemoved.test(initialState) == false) {
        final ClusterStateObserver clusterStateObserver = new ClusterStateObserver(initialState, clusterService, request.getTimeout(), logger, threadPool.getThreadContext());
        clusterStateObserver.waitForNextChange(new Listener() {

            @Override
            public void onNewClusterState(ClusterState state) {
                submitClearVotingConfigExclusionsTask(request, startTimeMillis, listener);
            }

            @Override
            public void onClusterServiceClose() {
                listener.onFailure(new OpenSearchException("cluster service closed while waiting for removal of nodes " + initialState.getVotingConfigExclusions()));
            }

            @Override
            public void onTimeout(TimeValue timeout) {
                listener.onFailure(new OpenSearchTimeoutException("timed out waiting for removal of nodes; if nodes should not be removed, set waitForRemoval to false. " + initialState.getVotingConfigExclusions()));
            }
        }, allExclusionsRemoved);
    } else {
        submitClearVotingConfigExclusionsTask(request, startTimeMillis, listener);
    }
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) Metadata(org.opensearch.cluster.metadata.Metadata) ThreadPool(org.opensearch.threadpool.ThreadPool) Priority(org.opensearch.common.Priority) TransportMasterNodeAction(org.opensearch.action.support.master.TransportMasterNodeAction) OpenSearchException(org.opensearch.OpenSearchException) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) ClusterState(org.opensearch.cluster.ClusterState) Inject(org.opensearch.common.inject.Inject) ActionListener(org.opensearch.action.ActionListener) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) StreamInput(org.opensearch.common.io.stream.StreamInput) TimeValue(org.opensearch.common.unit.TimeValue) Predicate(java.util.function.Predicate) ClusterBlockLevel(org.opensearch.cluster.block.ClusterBlockLevel) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) Listener(org.opensearch.cluster.ClusterStateObserver.Listener) TransportService(org.opensearch.transport.TransportService) ActionFilters(org.opensearch.action.support.ActionFilters) Logger(org.apache.logging.log4j.Logger) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) ClusterService(org.opensearch.cluster.service.ClusterService) LogManager(org.apache.logging.log4j.LogManager) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ClusterState(org.opensearch.cluster.ClusterState) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ActionListener(org.opensearch.action.ActionListener) Listener(org.opensearch.cluster.ClusterStateObserver.Listener) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) OpenSearchException(org.opensearch.OpenSearchException) TimeValue(org.opensearch.common.unit.TimeValue)

Example 2 with OpenSearchTimeoutException

use of org.opensearch.OpenSearchTimeoutException in project OpenSearch by opensearch-project.

the class ListenerTimeouts method wrapWithTimeout.

/**
 * Wraps a listener with a listener that can timeout. After the timeout period the
 * {@link ActionListener#onFailure(Exception)} will be called with a
 * {@link OpenSearchTimeoutException} if the listener has not already been completed.
 *
 * @param threadPool used to schedule the timeout
 * @param listener to that can timeout
 * @param timeout period before listener failed
 * @param executor to use for scheduling timeout
 * @param listenerName name of the listener for timeout exception
 * @return the wrapped listener that will timeout
 */
public static <Response> ActionListener<Response> wrapWithTimeout(ThreadPool threadPool, ActionListener<Response> listener, TimeValue timeout, String executor, String listenerName) {
    return wrapWithTimeout(threadPool, timeout, executor, listener, (ignore) -> {
        String timeoutMessage = "[" + listenerName + "]" + " timed out after [" + timeout + "]";
        listener.onFailure(new OpenSearchTimeoutException(timeoutMessage));
    });
}
Also used : OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException)

Example 3 with OpenSearchTimeoutException

use of org.opensearch.OpenSearchTimeoutException 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 OpenSearchTimeoutException

use of org.opensearch.OpenSearchTimeoutException in project OpenSearch by opensearch-project.

the class RestGetMappingAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
    getMappingsRequest.indices(indices);
    getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
    final TimeValue timeout = request.paramAsTime("master_timeout", getMappingsRequest.masterNodeTimeout());
    getMappingsRequest.masterNodeTimeout(timeout);
    getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
    return channel -> client.admin().indices().getMappings(getMappingsRequest, new RestActionListener<GetMappingsResponse>(channel) {

        @Override
        protected void processResponse(GetMappingsResponse getMappingsResponse) {
            final long startTimeMs = threadPool.relativeTimeInMillis();
            // Process serialization on GENERIC pool since the serialization of the raw mappings to XContent can be too slow to execute
            // on an IO thread
            threadPool.executor(ThreadPool.Names.MANAGEMENT).execute(ActionRunnable.wrap(this, l -> new RestBuilderListener<GetMappingsResponse>(channel) {

                @Override
                public RestResponse buildResponse(final GetMappingsResponse response, final XContentBuilder builder) throws Exception {
                    if (threadPool.relativeTimeInMillis() - startTimeMs > timeout.millis()) {
                        throw new OpenSearchTimeoutException("Timed out getting mappings");
                    }
                    builder.startObject();
                    response.toXContent(builder, request);
                    builder.endObject();
                    return new BytesRestResponse(RestStatus.OK, builder);
                }
            }.onResponse(getMappingsResponse)));
        }
    });
}
Also used : TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) ActionRunnable(org.opensearch.action.ActionRunnable) RestRequest(org.opensearch.rest.RestRequest) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse) ThreadPool(org.opensearch.threadpool.ThreadPool) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) RestStatus(org.opensearch.rest.RestStatus) GetMappingsRequest(org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) RestActionListener(org.opensearch.rest.action.RestActionListener) RestBuilderListener(org.opensearch.rest.action.RestBuilderListener) List(java.util.List) Arrays.asList(java.util.Arrays.asList) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) BaseRestHandler(org.opensearch.rest.BaseRestHandler) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) BytesRestResponse(org.opensearch.rest.BytesRestResponse) GetMappingsRequest(org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest) RestBuilderListener(org.opensearch.rest.action.RestBuilderListener) TimeValue(org.opensearch.common.unit.TimeValue) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 5 with OpenSearchTimeoutException

use of org.opensearch.OpenSearchTimeoutException in project OpenSearch by opensearch-project.

the class Node method start.

/**
 * Start the node. If the node is already started, this method is no-op.
 */
public Node start() throws NodeValidationException {
    if (!lifecycle.moveToStarted()) {
        return this;
    }
    logger.info("starting ...");
    pluginLifecycleComponents.forEach(LifecycleComponent::start);
    injector.getInstance(MappingUpdatedAction.class).setClient(client);
    injector.getInstance(IndicesService.class).start();
    injector.getInstance(IndicesClusterStateService.class).start();
    injector.getInstance(SnapshotsService.class).start();
    injector.getInstance(SnapshotShardsService.class).start();
    injector.getInstance(RepositoriesService.class).start();
    injector.getInstance(SearchService.class).start();
    injector.getInstance(FsHealthService.class).start();
    nodeService.getMonitorService().start();
    final ClusterService clusterService = injector.getInstance(ClusterService.class);
    final NodeConnectionsService nodeConnectionsService = injector.getInstance(NodeConnectionsService.class);
    nodeConnectionsService.start();
    clusterService.setNodeConnectionsService(nodeConnectionsService);
    injector.getInstance(GatewayService.class).start();
    Discovery discovery = injector.getInstance(Discovery.class);
    clusterService.getMasterService().setClusterStatePublisher(discovery::publish);
    // Start the transport service now so the publish address will be added to the local disco node in ClusterService
    TransportService transportService = injector.getInstance(TransportService.class);
    transportService.getTaskManager().setTaskResultsService(injector.getInstance(TaskResultsService.class));
    transportService.getTaskManager().setTaskCancellationService(new TaskCancellationService(transportService));
    transportService.start();
    assert localNodeFactory.getNode() != null;
    assert transportService.getLocalNode().equals(localNodeFactory.getNode()) : "transportService has a different local node than the factory provided";
    injector.getInstance(PeerRecoverySourceService.class).start();
    // Load (and maybe upgrade) the metadata stored on disk
    final GatewayMetaState gatewayMetaState = injector.getInstance(GatewayMetaState.class);
    gatewayMetaState.start(settings(), transportService, clusterService, injector.getInstance(MetaStateService.class), injector.getInstance(MetadataIndexUpgradeService.class), injector.getInstance(MetadataUpgrader.class), injector.getInstance(PersistedClusterStateService.class));
    if (Assertions.ENABLED) {
        try {
            assert injector.getInstance(MetaStateService.class).loadFullState().v1().isEmpty();
            final NodeMetadata nodeMetadata = NodeMetadata.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY, nodeEnvironment.nodeDataPaths());
            assert nodeMetadata != null;
            assert nodeMetadata.nodeVersion().equals(Version.CURRENT);
            assert nodeMetadata.nodeId().equals(localNodeFactory.getNode().getId());
        } catch (IOException e) {
            assert false : e;
        }
    }
    // we load the global state here (the persistent part of the cluster state stored on disk) to
    // pass it to the bootstrap checks to allow plugins to enforce certain preconditions based on the recovered state.
    final Metadata onDiskMetadata = gatewayMetaState.getPersistedState().getLastAcceptedState().metadata();
    // this is never null
    assert onDiskMetadata != null : "metadata is null but shouldn't";
    validateNodeBeforeAcceptingRequests(new BootstrapContext(environment, onDiskMetadata), transportService.boundAddress(), pluginsService.filterPlugins(Plugin.class).stream().flatMap(p -> p.getBootstrapChecks().stream()).collect(Collectors.toList()));
    clusterService.addStateApplier(transportService.getTaskManager());
    // start after transport service so the local disco is known
    // start before cluster service so that it can set initial state on ClusterApplierService
    discovery.start();
    clusterService.start();
    assert clusterService.localNode().equals(localNodeFactory.getNode()) : "clusterService has a different local node than the factory provided";
    transportService.acceptIncomingRequests();
    discovery.startInitialJoin();
    final TimeValue initialStateTimeout = DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.get(settings());
    configureNodeAndClusterIdStateListener(clusterService);
    if (initialStateTimeout.millis() > 0) {
        final ThreadPool thread = injector.getInstance(ThreadPool.class);
        ClusterState clusterState = clusterService.state();
        ClusterStateObserver observer = new ClusterStateObserver(clusterState, clusterService, null, logger, thread.getThreadContext());
        if (clusterState.nodes().getMasterNodeId() == null) {
            logger.debug("waiting to join the cluster. timeout [{}]", initialStateTimeout);
            final CountDownLatch latch = new CountDownLatch(1);
            observer.waitForNextChange(new ClusterStateObserver.Listener() {

                @Override
                public void onNewClusterState(ClusterState state) {
                    latch.countDown();
                }

                @Override
                public void onClusterServiceClose() {
                    latch.countDown();
                }

                @Override
                public void onTimeout(TimeValue timeout) {
                    logger.warn("timed out while waiting for initial discovery state - timeout: {}", initialStateTimeout);
                    latch.countDown();
                }
            }, state -> state.nodes().getMasterNodeId() != null, initialStateTimeout);
            try {
                latch.await();
            } catch (InterruptedException e) {
                throw new OpenSearchTimeoutException("Interrupted while waiting for initial discovery state");
            }
        }
    }
    injector.getInstance(HttpServerTransport.class).start();
    if (WRITE_PORTS_FILE_SETTING.get(settings())) {
        TransportService transport = injector.getInstance(TransportService.class);
        writePortsFile("transport", transport.boundAddress());
        HttpServerTransport http = injector.getInstance(HttpServerTransport.class);
        writePortsFile("http", http.boundAddress());
    }
    logger.info("started");
    pluginsService.filterPlugins(ClusterPlugin.class).forEach(ClusterPlugin::onNodeStarted);
    return this;
}
Also used : OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) SnapshotsService(org.opensearch.snapshots.SnapshotsService) SnapshotShardsService(org.opensearch.snapshots.SnapshotShardsService) NodeConnectionsService(org.opensearch.cluster.NodeConnectionsService) Metadata(org.opensearch.cluster.metadata.Metadata) NodeMetadata(org.opensearch.env.NodeMetadata) IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) MetadataUpgrader(org.opensearch.plugins.MetadataUpgrader) BootstrapContext(org.opensearch.bootstrap.BootstrapContext) TaskResultsService(org.opensearch.tasks.TaskResultsService) HttpServerTransport(org.opensearch.http.HttpServerTransport) GatewayMetaState(org.opensearch.gateway.GatewayMetaState) MetaStateService(org.opensearch.gateway.MetaStateService) IndicesClusterStateService(org.opensearch.indices.cluster.IndicesClusterStateService) LifecycleComponent(org.opensearch.common.component.LifecycleComponent) SearchService(org.opensearch.search.SearchService) PeerRecoverySourceService(org.opensearch.indices.recovery.PeerRecoverySourceService) TimeValue(org.opensearch.common.unit.TimeValue) FsHealthService(org.opensearch.monitor.fs.FsHealthService) ClusterState(org.opensearch.cluster.ClusterState) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterPlugin(org.opensearch.plugins.ClusterPlugin) Discovery(org.opensearch.discovery.Discovery) IndicesService(org.opensearch.indices.IndicesService) MetadataIndexUpgradeService(org.opensearch.cluster.metadata.MetadataIndexUpgradeService) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) GatewayService(org.opensearch.gateway.GatewayService) NodeMetadata(org.opensearch.env.NodeMetadata) ClusterService(org.opensearch.cluster.service.ClusterService) PersistentTasksClusterService(org.opensearch.persistent.PersistentTasksClusterService) RemoteClusterService(org.opensearch.transport.RemoteClusterService) TransportService(org.opensearch.transport.TransportService) SearchTransportService(org.opensearch.action.search.SearchTransportService) RepositoriesService(org.opensearch.repositories.RepositoriesService) MappingUpdatedAction(org.opensearch.cluster.action.index.MappingUpdatedAction) PersistedClusterStateService(org.opensearch.gateway.PersistedClusterStateService) TaskCancellationService(org.opensearch.tasks.TaskCancellationService)

Aggregations

OpenSearchTimeoutException (org.opensearch.OpenSearchTimeoutException)7 TimeValue (org.opensearch.common.unit.TimeValue)5 IOException (java.io.IOException)4 ActionListener (org.opensearch.action.ActionListener)3 ClusterState (org.opensearch.cluster.ClusterState)3 ClusterStateObserver (org.opensearch.cluster.ClusterStateObserver)3 ThreadPool (org.opensearch.threadpool.ThreadPool)3 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Predicate (java.util.function.Predicate)2 OpenSearchException (org.opensearch.OpenSearchException)2 Listener (org.opensearch.cluster.ClusterStateObserver.Listener)2 ClusterStateUpdateTask (org.opensearch.cluster.ClusterStateUpdateTask)2 ClusterBlockException (org.opensearch.cluster.block.ClusterBlockException)2 Metadata (org.opensearch.cluster.metadata.Metadata)2 ClusterService (org.opensearch.cluster.service.ClusterService)2 TransportService (org.opensearch.transport.TransportService)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1