Search in sources :

Example 1 with Role

use of org.elasticsearch.cluster.node.DiscoveryNode.Role in project elasticsearch by elastic.

the class ZenDiscoveryUnitTests method testFilterNonMasterPingResponse.

public void testFilterNonMasterPingResponse() {
    ArrayList<ZenPing.PingResponse> responses = new ArrayList<>();
    ArrayList<DiscoveryNode> masterNodes = new ArrayList<>();
    ArrayList<DiscoveryNode> allNodes = new ArrayList<>();
    for (int i = randomIntBetween(10, 20); i >= 0; i--) {
        Set<Role> roles = new HashSet<>(randomSubsetOf(Arrays.asList(Role.values())));
        DiscoveryNode node = new DiscoveryNode("node_" + i, "id_" + i, buildNewFakeTransportAddress(), Collections.emptyMap(), roles, Version.CURRENT);
        responses.add(new ZenPing.PingResponse(node, randomBoolean() ? null : node, new ClusterName("test"), randomLong()));
        allNodes.add(node);
        if (node.isMasterNode()) {
            masterNodes.add(node);
        }
    }
    boolean ignore = randomBoolean();
    List<ZenPing.PingResponse> filtered = ZenDiscovery.filterPingResponses(responses, ignore, logger);
    final List<DiscoveryNode> filteredNodes = filtered.stream().map(ZenPing.PingResponse::node).collect(Collectors.toList());
    if (ignore) {
        assertThat(filteredNodes, equalTo(masterNodes));
    } else {
        assertThat(filteredNodes, equalTo(allNodes));
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ArrayList(java.util.ArrayList) Role(org.elasticsearch.cluster.node.DiscoveryNode.Role) ClusterName(org.elasticsearch.cluster.ClusterName) HashSet(java.util.HashSet)

Example 2 with Role

use of org.elasticsearch.cluster.node.DiscoveryNode.Role in project elasticsearch by elastic.

the class InternalTestCluster method fullRestart.

/**
     * Restarts all nodes in the cluster. It first stops all nodes and then restarts all the nodes again.
     */
public synchronized void fullRestart(RestartCallback callback) throws Exception {
    int numNodesRestarted = 0;
    Map<Set<Role>, List<NodeAndClient>> nodesByRoles = new HashMap<>();
    Set[] rolesOrderedByOriginalStartupOrder = new Set[nextNodeId.get()];
    for (NodeAndClient nodeAndClient : nodes.values()) {
        callback.doAfterNodes(numNodesRestarted++, nodeAndClient.nodeClient());
        logger.info("Stopping node [{}] ", nodeAndClient.name);
        if (activeDisruptionScheme != null) {
            activeDisruptionScheme.removeFromNode(nodeAndClient.name, this);
        }
        nodeAndClient.closeNode();
        // delete data folders now, before we start other nodes that may claim it
        nodeAndClient.clearDataIfNeeded(callback);
        DiscoveryNode discoveryNode = getInstanceFromNode(ClusterService.class, nodeAndClient.node()).localNode();
        rolesOrderedByOriginalStartupOrder[nodeAndClient.nodeAndClientId] = discoveryNode.getRoles();
        nodesByRoles.computeIfAbsent(discoveryNode.getRoles(), k -> new ArrayList<>()).add(nodeAndClient);
    }
    assert nodesByRoles.values().stream().collect(Collectors.summingInt(List::size)) == nodes.size();
    //    will still belong to data nodes
    for (List<NodeAndClient> sameRoleNodes : nodesByRoles.values()) {
        Collections.shuffle(sameRoleNodes, random);
    }
    List<NodeAndClient> startUpOrder = new ArrayList<>();
    for (Set roles : rolesOrderedByOriginalStartupOrder) {
        if (roles == null) {
            // if some nodes were stopped, we want have a role for that ordinal
            continue;
        }
        final List<NodeAndClient> nodesByRole = nodesByRoles.get(roles);
        startUpOrder.add(nodesByRole.remove(0));
    }
    assert nodesByRoles.values().stream().collect(Collectors.summingInt(List::size)) == 0;
    // do two rounds to minimize pinging (mock zen pings pings with no delay and can create a lot of logs)
    for (NodeAndClient nodeAndClient : startUpOrder) {
        logger.info("resetting node [{}] ", nodeAndClient.name);
        // we already cleared data folders, before starting nodes up
        nodeAndClient.recreateNodeOnRestart(callback, false, autoManageMinMasterNodes ? getMinMasterNodes(getMasterNodesCount()) : -1);
    }
    startAndPublishNodesAndClients(startUpOrder);
    if (callback.validateClusterForming()) {
        validateClusterFormed();
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ByteSizeUnit(org.elasticsearch.common.unit.ByteSizeUnit) Arrays(java.util.Arrays) Nullable(org.elasticsearch.common.Nullable) Releasables(org.elasticsearch.common.lease.Releasables) NetworkModule(org.elasticsearch.common.network.NetworkModule) ZenDiscovery(org.elasticsearch.discovery.zen.ZenDiscovery) ThreadContext(org.elasticsearch.common.util.concurrent.ThreadContext) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) NodeValidationException(org.elasticsearch.node.NodeValidationException) SearchService(org.elasticsearch.search.SearchService) RecoverySettings(org.elasticsearch.indices.recovery.RecoverySettings) ClusterState(org.elasticsearch.cluster.ClusterState) Future(java.util.concurrent.Future) RandomNumbers(com.carrotsearch.randomizedtesting.generators.RandomNumbers) Map(java.util.Map) Role(org.elasticsearch.cluster.node.DiscoveryNode.Role) Path(java.nio.file.Path) RandomStrings(com.carrotsearch.randomizedtesting.generators.RandomStrings) ServiceDisruptionScheme(org.elasticsearch.test.disruption.ServiceDisruptionScheme) Transport(org.elasticsearch.transport.Transport) MappingUpdatedAction(org.elasticsearch.cluster.action.index.MappingUpdatedAction) Set(java.util.Set) PageCacheRecycler(org.elasticsearch.common.util.PageCacheRecycler) ESTestCase.assertBusy(org.elasticsearch.test.ESTestCase.assertBusy) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) TransportSettings(org.elasticsearch.transport.TransportSettings) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) ThrottlingAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) RandomPicks(com.carrotsearch.randomizedtesting.generators.RandomPicks) DiskThresholdSettings(org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings) TransportClient(org.elasticsearch.client.transport.TransportClient) ClusterService(org.elasticsearch.cluster.service.ClusterService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) ArrayList(java.util.ArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TcpTransport(org.elasticsearch.transport.TcpTransport) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) IndicesService(org.elasticsearch.indices.IndicesService) TransportService(org.elasticsearch.transport.TransportService) Loggers(org.elasticsearch.common.logging.Loggers) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) FileSystemUtils(org.elasticsearch.common.io.FileSystemUtils) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) OperationRouting(org.elasticsearch.cluster.routing.OperationRouting) Client(org.elasticsearch.client.Client) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) NodeService(org.elasticsearch.node.NodeService) SeedUtils(com.carrotsearch.randomizedtesting.SeedUtils) ExecutionException(java.util.concurrent.ExecutionException) LuceneTestCase.rarely(org.apache.lucene.util.LuceneTestCase.rarely) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) TreeMap(java.util.TreeMap) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) Assert(org.junit.Assert) ScriptService(org.elasticsearch.script.ScriptService) Builder(org.elasticsearch.common.settings.Settings.Builder) ElasticsearchAssertions.assertAcked(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked) ElasticsearchException(org.elasticsearch.ElasticsearchException) Environment(org.elasticsearch.env.Environment) Random(java.util.Random) TEST_NIGHTLY(org.apache.lucene.util.LuceneTestCase.TEST_NIGHTLY) Assert.assertThat(org.junit.Assert.assertThat) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SysGlobals(com.carrotsearch.randomizedtesting.SysGlobals) Assert.fail(org.junit.Assert.fail) ClusterName(org.elasticsearch.cluster.ClusterName) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) Flag(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag) NavigableMap(java.util.NavigableMap) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Engine(org.elasticsearch.index.engine.Engine) ESTestCase.randomFrom(org.elasticsearch.test.ESTestCase.randomFrom) MockTransportClient(org.elasticsearch.transport.MockTransportClient) List(java.util.List) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Matchers.equalTo(org.hamcrest.Matchers.equalTo) DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING(org.elasticsearch.discovery.zen.ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING) ElectMasterService(org.elasticsearch.discovery.zen.ElectMasterService) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) CommitStats(org.elasticsearch.index.engine.CommitStats) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) Function(java.util.function.Function) Strings(org.elasticsearch.common.Strings) ListTasksResponse(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse) HashSet(java.util.HashSet) TimeValue(org.elasticsearch.common.unit.TimeValue) Node(org.elasticsearch.node.Node) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ExecutorService(java.util.concurrent.ExecutorService) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) TaskInfo(org.elasticsearch.tasks.TaskInfo) MockNode(org.elasticsearch.node.MockNode) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) Iterator(java.util.Iterator) Plugin(org.elasticsearch.plugins.Plugin) ESTestCase.awaitBusy(org.elasticsearch.test.ESTestCase.awaitBusy) TimeUnit(java.util.concurrent.TimeUnit) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Closeable(java.io.Closeable) TaskManager(org.elasticsearch.tasks.TaskManager) Collections(java.util.Collections) ReplicationTask(org.elasticsearch.action.support.replication.ReplicationTask) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Set(java.util.Set) HashSet(java.util.HashSet) ClusterService(org.elasticsearch.cluster.service.ClusterService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Role

use of org.elasticsearch.cluster.node.DiscoveryNode.Role in project elasticsearch by elastic.

the class UnicastZenPingTests method startServices.

private NetworkHandle startServices(final Settings settings, final ThreadPool threadPool, final String nodeId, final Version version, final BiFunction<Settings, Version, Transport> supplier, final Set<Role> nodeRoles) {
    final Settings nodeSettings = Settings.builder().put(settings).put("node.name", nodeId).put(TransportService.TRACE_LOG_INCLUDE_SETTING.getKey(), "internal:discovery/zen/unicast").build();
    final Transport transport = supplier.apply(nodeSettings, version);
    final MockTransportService transportService = new MockTransportService(nodeSettings, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> new DiscoveryNode(nodeId, nodeId, boundAddress.publishAddress(), emptyMap(), nodeRoles, version), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    final ConcurrentMap<TransportAddress, AtomicInteger> counters = ConcurrentCollections.newConcurrentMap();
    transportService.addTracer(new MockTransportService.Tracer() {

        @Override
        public void requestSent(DiscoveryNode node, long requestId, String action, TransportRequestOptions options) {
            counters.computeIfAbsent(node.getAddress(), k -> new AtomicInteger());
            counters.get(node.getAddress()).incrementAndGet();
        }
    });
    return new NetworkHandle(transport.boundAddress().publishAddress(), transportService, transportService.getLocalNode(), counters);
}
Also used : Arrays(java.util.Arrays) BigArrays(org.elasticsearch.common.util.BigArrays) ConcurrentCollections(org.elasticsearch.common.util.concurrent.ConcurrentCollections) BiFunction(java.util.function.BiFunction) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) InetAddress(java.net.InetAddress) STATE_NOT_RECOVERED_BLOCK(org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK) ClusterState(org.elasticsearch.cluster.ClusterState) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ClusterName(org.elasticsearch.cluster.ClusterName) Role(org.elasticsearch.cluster.node.DiscoveryNode.Role) ThreadFactory(java.util.concurrent.ThreadFactory) EnumSet(java.util.EnumSet) Transport(org.elasticsearch.transport.Transport) Collection(java.util.Collection) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Version(org.elasticsearch.Version) TransportAddress(org.elasticsearch.common.transport.TransportAddress) TransportConnectionListener(org.elasticsearch.transport.TransportConnectionListener) TransportSettings(org.elasticsearch.transport.TransportSettings) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) TransportException(org.elasticsearch.transport.TransportException) NetworkAddress(org.elasticsearch.common.network.NetworkAddress) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) Matchers(org.mockito.Matchers) HashMap(java.util.HashMap) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) AtomicReference(java.util.concurrent.atomic.AtomicReference) CheckedBiConsumer(org.elasticsearch.common.CheckedBiConsumer) Stack(java.util.Stack) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NetworkService(org.elasticsearch.common.network.NetworkService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) TimeValue(org.elasticsearch.common.unit.TimeValue) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ESTestCase(org.elasticsearch.test.ESTestCase) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportService(org.elasticsearch.transport.TransportService) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ConnectionProfile(org.elasticsearch.transport.ConnectionProfile) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Matchers.empty(org.hamcrest.Matchers.empty) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) Collections.emptySet(java.util.Collections.emptySet) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) VersionUtils(org.elasticsearch.test.VersionUtils) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Closeable(java.io.Closeable) Collections(java.util.Collections) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) Transport(org.elasticsearch.transport.Transport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) Settings(org.elasticsearch.common.settings.Settings) TransportSettings(org.elasticsearch.transport.TransportSettings)

Aggregations

ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ClusterName (org.elasticsearch.cluster.ClusterName)3 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)3 Role (org.elasticsearch.cluster.node.DiscoveryNode.Role)3 Closeable (java.io.Closeable)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Collectors (java.util.stream.Collectors)2