Search in sources :

Example 11 with TimeValue

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

the class DelayedAllocationService method scheduleIfNeeded.

/**
 * Figure out if an existing scheduled reroute is good enough or whether we need to cancel and reschedule.
 */
private synchronized void scheduleIfNeeded(long currentNanoTime, ClusterState state) {
    assertClusterOrMasterStateThread();
    long nextDelayNanos = UnassignedInfo.findNextDelayedAllocation(currentNanoTime, state);
    if (nextDelayNanos < 0) {
        LOGGER.trace("no need to schedule reroute - no delayed unassigned shards");
        removeTaskAndCancel();
    } else {
        TimeValue nextDelay = TimeValue.timeValueNanos(nextDelayNanos);
        final boolean earlierRerouteNeeded;
        DelayedRerouteTask existingTask = delayedRerouteTask.get();
        DelayedRerouteTask newTask = new DelayedRerouteTask(nextDelay, currentNanoTime);
        if (existingTask == null) {
            earlierRerouteNeeded = true;
        } else if (newTask.scheduledTimeToRunInNanos() < existingTask.scheduledTimeToRunInNanos()) {
            // we need an earlier delayed reroute
            LOGGER.trace("cancelling existing delayed reroute task as delayed reroute has to happen [{}] earlier", TimeValue.timeValueNanos(existingTask.scheduledTimeToRunInNanos() - newTask.scheduledTimeToRunInNanos()));
            existingTask.cancelScheduling();
            earlierRerouteNeeded = true;
        } else {
            earlierRerouteNeeded = false;
        }
        if (earlierRerouteNeeded) {
            LOGGER.info("scheduling reroute for delayed shards in [{}] ({} delayed shards)", nextDelay, UnassignedInfo.getNumberOfDelayedUnassigned(state));
            DelayedRerouteTask currentTask = delayedRerouteTask.getAndSet(newTask);
            assert existingTask == currentTask || currentTask == null;
            newTask.schedule();
        } else {
            LOGGER.trace("no need to reschedule delayed reroute - currently scheduled delayed reroute in [{}] is enough", nextDelay);
        }
    }
}
Also used : TimeValue(io.crate.common.unit.TimeValue)

Example 12 with TimeValue

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

the class TcpTransport method initiateConnection.

private List<TcpChannel> initiateConnection(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) {
    int numConnections = connectionProfile.getNumConnections();
    assert numConnections > 0 : "A connection profile must be configured with at least one connection";
    final List<TcpChannel> channels = new ArrayList<>(numConnections);
    for (int i = 0; i < numConnections; ++i) {
        try {
            TcpChannel channel = initiateChannel(node);
            logger.trace(() -> new ParameterizedMessage("Tcp transport client channel opened: {}", channel));
            channels.add(channel);
        } catch (ConnectTransportException e) {
            CloseableChannel.closeChannels(channels, false);
            listener.onFailure(e);
            return channels;
        } catch (Exception e) {
            CloseableChannel.closeChannels(channels, false);
            listener.onFailure(new ConnectTransportException(node, "general node connection failure", e));
            return channels;
        }
    }
    ChannelsConnectedListener channelsConnectedListener = new ChannelsConnectedListener(node, connectionProfile, channels, new ThreadedActionListener<>(logger, threadPool, ThreadPool.Names.GENERIC, listener, false));
    for (TcpChannel channel : channels) {
        channel.addConnectListener(channelsConnectedListener);
    }
    TimeValue connectTimeout = connectionProfile.getConnectTimeout();
    threadPool.schedule(channelsConnectedListener::onTimeout, connectTimeout, ThreadPool.Names.GENERIC);
    return channels;
}
Also used : ArrayList(java.util.ArrayList) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ElasticsearchException(org.elasticsearch.ElasticsearchException) StreamCorruptedException(java.io.StreamCorruptedException) CancelledKeyException(java.nio.channels.CancelledKeyException) NetworkExceptionHelper.isCloseConnectionException(org.elasticsearch.common.transport.NetworkExceptionHelper.isCloseConnectionException) BindException(java.net.BindException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NetworkExceptionHelper.isConnectException(org.elasticsearch.common.transport.NetworkExceptionHelper.isConnectException) TimeValue(io.crate.common.unit.TimeValue)

Example 13 with TimeValue

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

the class TransportKeepAlive method registerNodeConnection.

void registerNodeConnection(List<TcpChannel> nodeChannels, ConnectionProfile connectionProfile) {
    TimeValue pingInterval = connectionProfile.getPingInterval();
    if (pingInterval.millis() < 0) {
        return;
    }
    final ScheduledPing scheduledPing = pingIntervals.computeIfAbsent(pingInterval, ScheduledPing::new);
    scheduledPing.ensureStarted();
    for (TcpChannel channel : nodeChannels) {
        scheduledPing.addChannel(channel);
        channel.addCloseListener(ActionListener.wrap(() -> {
            scheduledPing.removeChannel(channel);
        }));
    }
}
Also used : TimeValue(io.crate.common.unit.TimeValue)

Example 14 with TimeValue

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

the class LimitedBackoffPolicyTest method testLimit.

@Test
public void testLimit() throws Exception {
    int maxDelay = 1000;
    LimitedExponentialBackoff policy = new LimitedExponentialBackoff(0, 1000, maxDelay);
    for (TimeValue val : policy) {
        assertThat(val.millis(), Matchers.lessThanOrEqualTo((long) maxDelay));
    }
}
Also used : TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

Example 15 with TimeValue

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

the class MasterService method onPublicationSuccess.

void onPublicationSuccess(ClusterChangedEvent clusterChangedEvent, TaskOutputs taskOutputs) {
    final long notificationStartTime = threadPool.relativeTimeInMillis();
    taskOutputs.processedDifferentClusterState(clusterChangedEvent.previousState(), clusterChangedEvent.state());
    try {
        taskOutputs.clusterStatePublished(clusterChangedEvent);
    } catch (Exception e) {
        LOGGER.error(() -> new ParameterizedMessage("exception thrown while notifying executor of new cluster state publication [{}]", clusterChangedEvent.source()), e);
    }
    final TimeValue executionTime = getTimeSince(notificationStartTime);
    logExecutionTime(executionTime, "notify listeners on successful publication of cluster state (version: " + clusterChangedEvent.state().version() + ", uuid: " + clusterChangedEvent.state().stateUUID() + ')', clusterChangedEvent.source());
}
Also used : ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ProcessClusterEventTimeoutException(org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException) FailedToCommitClusterStateException(org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) 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