Search in sources :

Example 1 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class RetryOnFailureResultReceiver method fail.

@Override
public void fail(@Nonnull Throwable wrappedError) {
    final Throwable error = SQLExceptions.unwrap(wrappedError);
    if (attempt <= Constants.MAX_SHARD_MISSING_RETRIES && (SQLExceptions.isShardFailure(error) || error instanceof ConnectTransportException || indexWasTemporaryUnavailable(error))) {
        if (clusterService.state().blocks().hasGlobalBlockWithStatus(RestStatus.SERVICE_UNAVAILABLE)) {
            delegate.fail(error);
        } else {
            ClusterStateObserver clusterStateObserver = new ClusterStateObserver(initialState, clusterService, null, LOGGER);
            clusterStateObserver.waitForNextChange(new ClusterStateObserver.Listener() {

                @Override
                public void onNewClusterState(ClusterState state) {
                    attempt += 1;
                    retry();
                }

                @Override
                public void onClusterServiceClose() {
                    delegate.fail(error);
                }

                @Override
                public void onTimeout(TimeValue timeout) {
                    delegate.fail(error);
                }
            });
        }
    } else {
        delegate.fail(error);
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) TimeValue(io.crate.common.unit.TimeValue)

Example 2 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class TransportClusterHealthAction method executeHealth.

private void executeHealth(final ClusterHealthRequest request, final ClusterState currentState, final ActionListener<ClusterHealthResponse> listener, final int waitCount, final Consumer<ClusterState> onNewClusterStateAfterDelay) {
    if (request.timeout().millis() == 0) {
        listener.onResponse(getResponse(request, currentState, waitCount, true));
        return;
    }
    final Predicate<ClusterState> validationPredicate = newState -> validateRequest(request, newState, waitCount);
    if (validationPredicate.test(currentState)) {
        listener.onResponse(getResponse(request, currentState, waitCount, false));
    } else {
        final ClusterStateObserver observer = new ClusterStateObserver(currentState, clusterService, null, LOGGER);
        final ClusterStateObserver.Listener stateListener = new ClusterStateObserver.Listener() {

            @Override
            public void onNewClusterState(ClusterState newState) {
                onNewClusterStateAfterDelay.accept(newState);
            }

            @Override
            public void onClusterServiceClose() {
                listener.onFailure(new IllegalStateException("ClusterService was close during health call"));
            }

            @Override
            public void onTimeout(TimeValue timeout) {
                listener.onResponse(getResponse(request, observer.setAndGetObservedState(), waitCount, true));
            }
        };
        observer.waitForNextChange(stateListener, validationPredicate, request.timeout());
    }
}
Also used : NotMasterException(org.elasticsearch.cluster.NotMasterException) ClusterService(org.elasticsearch.cluster.service.ClusterService) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Strings(org.elasticsearch.common.Strings) Inject(org.elasticsearch.common.inject.Inject) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Settings(org.elasticsearch.common.settings.Settings) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) TransportMasterNodeReadAction(org.elasticsearch.action.support.master.TransportMasterNodeReadAction) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportService(org.elasticsearch.transport.TransportService) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) Predicate(java.util.function.Predicate) IOException(java.io.IOException) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) Consumer(java.util.function.Consumer) Logger(org.apache.logging.log4j.Logger) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TimeValue(io.crate.common.unit.TimeValue) LocalClusterUpdateTask(org.elasticsearch.cluster.LocalClusterUpdateTask) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) LogManager(org.apache.logging.log4j.LogManager) ActionListener(org.elasticsearch.action.ActionListener) GatewayAllocator(org.elasticsearch.gateway.GatewayAllocator) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) ActionListener(org.elasticsearch.action.ActionListener) TimeValue(io.crate.common.unit.TimeValue)

Example 3 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

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);
        clusterStateObserver.waitForNextChange(new Listener() {

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

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

            @Override
            public void onTimeout(TimeValue timeout) {
                listener.onFailure(new ElasticsearchTimeoutException("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 : ElasticsearchException(org.elasticsearch.ElasticsearchException) Priority(org.elasticsearch.common.Priority) Listener(org.elasticsearch.cluster.ClusterStateObserver.Listener) Predicate(java.util.function.Predicate) ClusterService(org.elasticsearch.cluster.service.ClusterService) IOException(java.io.IOException) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) Names(org.elasticsearch.threadpool.ThreadPool.Names) Inject(org.elasticsearch.common.inject.Inject) TransportMasterNodeAction(org.elasticsearch.action.support.master.TransportMasterNodeAction) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) ClusterState(org.elasticsearch.cluster.ClusterState) Metadata(org.elasticsearch.cluster.metadata.Metadata) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TimeValue(io.crate.common.unit.TimeValue) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportService(org.elasticsearch.transport.TransportService) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ActionListener(org.elasticsearch.action.ActionListener) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) Listener(org.elasticsearch.cluster.ClusterStateObserver.Listener) ActionListener(org.elasticsearch.action.ActionListener) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) ElasticsearchException(org.elasticsearch.ElasticsearchException) TimeValue(io.crate.common.unit.TimeValue)

Example 4 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class UDCService method doStart.

@Override
protected void doStart() throws ElasticsearchException {
    String url = UDC_URL_SETTING.get(settings);
    TimeValue initialDelay = UDC_INITIAL_DELAY_SETTING.get(settings);
    TimeValue interval = UDC_INTERVAL_SETTING.get(settings);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Starting with delay {} and period {}.", initialDelay.getSeconds(), interval.getSeconds());
    }
    PingTask pingTask = new PingTask(clusterService, extendedNodeInfo, url);
    timer.scheduleAtFixedRate(pingTask, initialDelay.millis(), interval.millis());
}
Also used : PingTask(io.crate.udc.ping.PingTask) TimeValue(io.crate.common.unit.TimeValue)

Example 5 with TimeValue

use of io.crate.common.unit.TimeValue in project crate by crate.

the class ProjectionToProjectorVisitor method visitDeleteProjection.

@Override
public Projector visitDeleteProjection(DeleteProjection projection, Context context) {
    checkShardLevel("Delete projection can only be executed on a shard");
    TimeValue reqTimeout = ShardingUpsertExecutor.BULK_REQUEST_TIMEOUT_SETTING.get(settings);
    ShardDMLExecutor<?, ?, ?, ?> shardDMLExecutor = new ShardDMLExecutor<>(context.jobId, ShardDMLExecutor.DEFAULT_BULK_SIZE, threadPool.scheduler(), threadPool.executor(ThreadPool.Names.SEARCH), resolveUidCollectExpression(context.txnCtx, projection.uidSymbol()), clusterService, nodeJobsCounter, () -> new ShardDeleteRequest(shardId, context.jobId).timeout(reqTimeout), ShardDeleteRequest.Item::new, transportActionProvider.transportShardDeleteAction()::execute, ShardDMLExecutor.ROW_COUNT_COLLECTOR);
    return new DMLProjector(shardDMLExecutor);
}
Also used : ShardDeleteRequest(io.crate.execution.dml.delete.ShardDeleteRequest) ShardDMLExecutor(io.crate.execution.engine.indexing.ShardDMLExecutor) DMLProjector(io.crate.execution.engine.indexing.DMLProjector) TimeValue(io.crate.common.unit.TimeValue)

Aggregations

TimeValue (io.crate.common.unit.TimeValue)75 Test (org.junit.Test)23 ClusterState (org.elasticsearch.cluster.ClusterState)20 IOException (java.io.IOException)17 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)12 ActionListener (org.elasticsearch.action.ActionListener)12 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)11 ArrayList (java.util.ArrayList)10 ThreadPool (org.elasticsearch.threadpool.ThreadPool)10 ElasticsearchException (org.elasticsearch.ElasticsearchException)9 Settings (org.elasticsearch.common.settings.Settings)9 Logger (org.apache.logging.log4j.Logger)8 ClusterStateUpdateTask (org.elasticsearch.cluster.ClusterStateUpdateTask)8 ClusterService (org.elasticsearch.cluster.service.ClusterService)8 List (java.util.List)7 LogManager (org.apache.logging.log4j.LogManager)7 Version (org.elasticsearch.Version)7 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)6 ClusterStateObserver (org.elasticsearch.cluster.ClusterStateObserver)6 StreamInput (org.elasticsearch.common.io.stream.StreamInput)6