Java Code Examples for org.elasticsearch.threadpool.ThreadPool#terminate()

The following examples show how to use org.elasticsearch.threadpool.ThreadPool#terminate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClusterApplierService.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected synchronized void doStop() {
    for (NotifyTimeout onGoingTimeout : onGoingTimeouts) {
        onGoingTimeout.cancel();
        try {
            onGoingTimeout.cancel();
            onGoingTimeout.listener.onClose();
        } catch (Exception ex) {
            LOGGER.debug("failed to notify listeners on shutdown", ex);
        }
    }
    ThreadPool.terminate(threadPoolExecutor, 10, TimeUnit.SECONDS);
    // close timeout listeners that did not have an ongoing timeout
    timeoutClusterStateListeners.forEach(TimeoutClusterStateListener::onClose);
    removeListener(localNodeMasterListeners);
}
 
Example 2
Source File: UnicastZenPing.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void doClose() {
    transportService.removeHandler(ACTION_NAME);
    ThreadPool.terminate(unicastConnectExecutor, 0, TimeUnit.SECONDS);
    try {
        IOUtils.close(receivedResponses.values());
    } catch (IOException e) {
        throw new ElasticsearchException("Error wile closing send ping handlers", e);
    }
    closed = true;
}
 
Example 3
Source File: ConcurrentSeqNoVersioningIT.java    From crate with Apache License 2.0 5 votes vote down vote up
void assertLinearizable() {
    logger.info("--> Linearizability checking history of size: {} for key: {} and initialVersion: {}: {}", history.size(),
                id, initialVersion, history);
    LinearizabilityChecker.SequentialSpec spec = new CASSequentialSpec(initialVersion);

    boolean linearizable = false;
    try {
        final ScheduledThreadPoolExecutor scheduler = Scheduler.initScheduler(Settings.EMPTY);
        final AtomicBoolean abort = new AtomicBoolean();
        // Large histories can be problematic and have the linearizability checker run OOM
        // Bound the time how long the checker can run on such histories (Values empirically determined)
        if (history.size() > 300) {
            scheduler.schedule(() -> abort.set(true), 10, TimeUnit.SECONDS);
        }
        linearizable = new LinearizabilityChecker().isLinearizable(spec, history, missingResponseGenerator(), abort::get);
        ThreadPool.terminate(scheduler, 1, TimeUnit.SECONDS);
        if (abort.get() && linearizable == false) {
            linearizable = true; // let the test pass
        }
    } finally {
        // implicitly test that we can serialize all histories.
        String serializedHistory = base64Serialize(history);
        if (linearizable == false) {
            // we dump base64 encoded data, since the nature of this test is that it does not reproduce even with same seed.
            logger.error("Linearizability check failed for id: {}. Spec: {}, initial version: {}, serialized history: {}",
                         id, spec, initialVersion, serializedHistory);
        }
    }
    assertTrue("Must be linearizable", linearizable);
}
 
Example 4
Source File: InternalClusterService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void doStop() {
    FutureUtils.cancel(this.reconnectToNodes);
    for (NotifyTimeout onGoingTimeout : onGoingTimeouts) {
        onGoingTimeout.cancel();
        onGoingTimeout.listener.onClose();
    }
    ThreadPool.terminate(updateTasksExecutor, 10, TimeUnit.SECONDS);
    remove(localNodeMasterListeners);
}
 
Example 5
Source File: ESTestCase.java    From crate with Apache License 2.0 5 votes vote down vote up
public static boolean terminate(ExecutorService... services) {
    boolean terminated = true;
    for (ExecutorService service : services) {
        if (service != null) {
            terminated &= ThreadPool.terminate(service, 10, TimeUnit.SECONDS);
        }
    }
    return terminated;
}
 
Example 6
Source File: IndexShardTestCase.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void tearDown() throws Exception {
    try {
        ThreadPool.terminate(threadPool, 30, TimeUnit.SECONDS);
    } finally {
        super.tearDown();
    }
}
 
Example 7
Source File: CrateDummyClusterServiceUnitTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void shutdownThreadPool() {
    ThreadPool.terminate(THREAD_POOL, 30, TimeUnit.SECONDS);
}
 
Example 8
Source File: AbstractADTest.java    From anomaly-detection with Apache License 2.0 4 votes vote down vote up
protected static void tearDownThreadPool() {
    ThreadPool.terminate(threadPool, 30, TimeUnit.SECONDS);
    threadPool = null;
}
 
Example 9
Source File: BlobIndicesServiceTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@After
public void stop() throws Exception {
    IOUtils.closeWhileHandlingException(clusterService);
    ThreadPool.terminate(threadPool, 30, TimeUnit.SECONDS);
}
 
Example 10
Source File: ESTestCase.java    From crate with Apache License 2.0 4 votes vote down vote up
public static boolean terminate(ThreadPool threadPool) {
    return ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
}
 
Example 11
Source File: CoordinatorTests.java    From crate with Apache License 2.0 4 votes vote down vote up
void stabilise(long stabilisationDurationMillis) {
    assertThat("stabilisation requires default delay variability (and proper cleanup of raised variability)",
        deterministicTaskQueue.getExecutionDelayVariabilityMillis(), lessThanOrEqualTo(DEFAULT_DELAY_VARIABILITY));
    assertFalse("stabilisation requires stable storage", disruptStorage);

    bootstrapIfNecessary();

    runFor(stabilisationDurationMillis, "stabilising");

    final ClusterNode leader = getAnyLeader();
    final long leaderTerm = leader.coordinator.getCurrentTerm();
    final Matcher<Long> isEqualToLeaderVersion = equalTo(leader.coordinator.getLastAcceptedState().getVersion());
    final String leaderId = leader.getId();

    assertTrue(leaderId + " has been bootstrapped", leader.coordinator.isInitialConfigurationSet());
    assertTrue(leaderId + " exists in its last-applied state", leader.getLastAppliedClusterState().getNodes().nodeExists(leaderId));
    assertThat(leaderId + " has applied its state ", leader.getLastAppliedClusterState().getVersion(), isEqualToLeaderVersion);

    for (final ClusterNode clusterNode : clusterNodes) {
        final String nodeId = clusterNode.getId();
        assertFalse(nodeId + " should not have an active publication", clusterNode.coordinator.publicationInProgress());

        if (clusterNode == leader) {
            continue;
        }

        if (isConnectedPair(leader, clusterNode)) {
            assertThat(nodeId + " is a follower of " + leaderId, clusterNode.coordinator.getMode(), is(FOLLOWER));
            assertThat(nodeId + " has the same term as " + leaderId, clusterNode.coordinator.getCurrentTerm(), is(leaderTerm));
            assertTrue(nodeId + " has voted for " + leaderId, leader.coordinator.hasJoinVoteFrom(clusterNode.getLocalNode()));
            assertThat(nodeId + " has the same accepted state as " + leaderId,
                clusterNode.coordinator.getLastAcceptedState().getVersion(), isEqualToLeaderVersion);
            if (clusterNode.getClusterStateApplyResponse() == ClusterStateApplyResponse.SUCCEED) {
                assertThat(nodeId + " has the same applied state as " + leaderId,
                    clusterNode.getLastAppliedClusterState().getVersion(), isEqualToLeaderVersion);
                assertTrue(nodeId + " is in its own latest applied state",
                    clusterNode.getLastAppliedClusterState().getNodes().nodeExists(nodeId));
            }
            assertTrue(nodeId + " is in the latest applied state on " + leaderId,
                leader.getLastAppliedClusterState().getNodes().nodeExists(nodeId));
            assertTrue(nodeId + " has been bootstrapped", clusterNode.coordinator.isInitialConfigurationSet());
            assertThat(nodeId + " has correct master", clusterNode.getLastAppliedClusterState().nodes().getMasterNode(),
                equalTo(leader.getLocalNode()));
            assertThat(nodeId + " has no NO_MASTER_BLOCK",
                clusterNode.getLastAppliedClusterState().blocks().hasGlobalBlockWithId(NO_MASTER_BLOCK_ID), equalTo(false));
        } else {
            assertThat(nodeId + " is not following " + leaderId, clusterNode.coordinator.getMode(), is(CANDIDATE));
            assertThat(nodeId + " has no master", clusterNode.getLastAppliedClusterState().nodes().getMasterNode(), nullValue());
            assertThat(nodeId + " has NO_MASTER_BLOCK",
                clusterNode.getLastAppliedClusterState().blocks().hasGlobalBlockWithId(NO_MASTER_BLOCK_ID), equalTo(true));
            assertFalse(nodeId + " is not in the applied state on " + leaderId,
                leader.getLastAppliedClusterState().getNodes().nodeExists(nodeId));
        }
    }

    final Set<String> connectedNodeIds
        = clusterNodes.stream().filter(n -> isConnectedPair(leader, n)).map(ClusterNode::getId).collect(Collectors.toSet());

    assertThat(leader.getLastAppliedClusterState().getNodes().getSize(), equalTo(connectedNodeIds.size()));

    final ClusterState lastAcceptedState = leader.coordinator.getLastAcceptedState();
    final VotingConfiguration lastCommittedConfiguration = lastAcceptedState.getLastCommittedConfiguration();
    assertTrue(connectedNodeIds + " should be a quorum of " + lastCommittedConfiguration,
        lastCommittedConfiguration.hasQuorum(connectedNodeIds));
    assertThat("leader " + leader.getLocalNode() + " should be part of voting configuration " + lastCommittedConfiguration,
        lastCommittedConfiguration.getNodeIds(), IsCollectionContaining.hasItem(leader.getLocalNode().getId()));

    assertThat("no reconfiguration is in progress",
        lastAcceptedState.getLastCommittedConfiguration(), equalTo(lastAcceptedState.getLastAcceptedConfiguration()));
    assertThat("current configuration is already optimal",
        leader.improveConfiguration(lastAcceptedState), sameInstance(lastAcceptedState));

    logger.info("checking linearizability of history with size {}: {}", history.size(), history);
    final AtomicBoolean abort = new AtomicBoolean();
    // Large histories can be problematic and have the linearizability checker run OOM
    // Bound the time how long the checker can run on such histories (Values empirically determined)
    final ScheduledThreadPoolExecutor scheduler = Scheduler.initScheduler(Settings.EMPTY);
    try {
        if (history.size() > 300) {
            scheduler.schedule(() -> abort.set(true), 10, TimeUnit.SECONDS);
        }
        final boolean linearizable = linearizabilityChecker.isLinearizable(spec, history, i -> null, abort::get);
        if (abort.get() == false) {
            assertTrue("history not linearizable: " + history, linearizable);
        }
    } finally {
        ThreadPool.terminate(scheduler, 1, TimeUnit.SECONDS);
    }
    logger.info("linearizability check completed");
}
 
Example 12
Source File: NodeJoinTests.java    From crate with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void afterClass() {
    ThreadPool.terminate(threadPool, 30, TimeUnit.SECONDS);
    threadPool = null;
}
 
Example 13
Source File: MasterService.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected synchronized void doStop() {
    ThreadPool.terminate(threadPoolExecutor, 10, TimeUnit.SECONDS);
}
 
Example 14
Source File: SeedHostsResolver.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected void doStop() {
    cancellableThreads.cancel("stopping SeedHostsResolver");
    ThreadPool.terminate(executorService.get(), 10, TimeUnit.SECONDS);
}
 
Example 15
Source File: TransportClient.java    From elasticsearch-helper with Apache License 2.0 4 votes vote down vote up
public TransportClient build() {
    Settings settings = InternalSettingsPreparer.prepareSettings(this.settings);
    settings = settingsBuilder()
            .put("transport.ping.schedule", this.settings.get("ping.interval", "30s"))
            .put(settings)
            .put("network.server", false)
            .put("node.client", true)
            .put(CLIENT_TYPE_SETTING, CLIENT_TYPE)
            .build();
    PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses);
    this.settings = pluginsService.updatedSettings();
    Version version = Version.CURRENT;
    final ThreadPool threadPool = new ThreadPool(settings);
    final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();

    boolean success = false;
    try {
        ModulesBuilder modules = new ModulesBuilder();
        modules.add(new Version.Module(version));
        // plugin modules must be added here, before others or we can get crazy injection errors...
        for (Module pluginModule : pluginsService.nodeModules()) {
            modules.add(pluginModule);
        }
        modules.add(new PluginsModule(pluginsService));
        modules.add(new SettingsModule(this.settings));
        modules.add(new NetworkModule(namedWriteableRegistry));
        modules.add(new ClusterNameModule(this.settings));
        modules.add(new ThreadPoolModule(threadPool));
        modules.add(new TransportModule(this.settings, namedWriteableRegistry));
        modules.add(new SearchModule() {
            @Override
            protected void configure() {
                // noop
            }
        });
        modules.add(new ActionModule(true));
        modules.add(new ClientTransportModule(hostFailedListener));
        modules.add(new CircuitBreakerModule(this.settings));
        pluginsService.processModules(modules);
        Injector injector = modules.createInjector();
        injector.getInstance(TransportService.class).start();
        TransportClient transportClient = new TransportClient(injector);
        success = true;
        return transportClient;
    } finally {
        if (!success) {
            ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
        }
    }
}
 
Example 16
Source File: LocalTransport.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected void doClose() {
    ThreadPool.terminate(workers, 10, TimeUnit.SECONDS);
}
 
Example 17
Source File: TransportClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a new instance of the transport client.
 */
public TransportClient build() {
    Settings settings = InternalSettingsPreparer.prepareSettings(this.settings);
    settings = settingsBuilder()
            .put(NettyTransport.PING_SCHEDULE, "5s") // enable by default the transport schedule ping interval
            .put(settings)
            .put("network.server", false)
            .put("node.client", true)
            .put(CLIENT_TYPE_SETTING, CLIENT_TYPE)
            .build();

    PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses);
    this.settings = pluginsService.updatedSettings();

    Version version = Version.CURRENT;

    final ThreadPool threadPool = new ThreadPool(settings);
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();

    boolean success = false;
    try {
        ModulesBuilder modules = new ModulesBuilder();
        modules.add(new Version.Module(version));
        // plugin modules must be added here, before others or we can get crazy injection errors...
        for (Module pluginModule : pluginsService.nodeModules()) {
            modules.add(pluginModule);
        }
        modules.add(new PluginsModule(pluginsService));
        modules.add(new SettingsModule(this.settings));
        modules.add(new NetworkModule(namedWriteableRegistry));
        modules.add(new ClusterNameModule(this.settings));
        modules.add(new ThreadPoolModule(threadPool));
        modules.add(new TransportModule(this.settings, namedWriteableRegistry));
        modules.add(new SearchModule() {
            @Override
            protected void configure() {
                // noop
            }
        });
        modules.add(new ActionModule(true));
        modules.add(new ClientTransportModule());
        modules.add(new CircuitBreakerModule(this.settings));

        pluginsService.processModules(modules);

        Injector injector = modules.createInjector();
        final TransportService transportService = injector.getInstance(TransportService.class);
        transportService.start();
        transportService.acceptIncomingRequests();

        TransportClient transportClient = new TransportClient(injector);
        success = true;
        return transportClient;
    } finally {
        if (!success) {
            ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
        }
    }
}
 
Example 18
Source File: RecoverySettings.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void close() {
    ThreadPool.terminate(concurrentStreamPool, 1, TimeUnit.SECONDS);
    ThreadPool.terminate(concurrentSmallFileStreamPool, 1, TimeUnit.SECONDS);
}