Search in sources :

Example 31 with Settings.builder

use of org.elasticsearch.common.settings.Settings.builder in project crate by crate.

the class CoordinatorTests method testSingleNodeDiscoveryWithoutQuorum.

public void testSingleNodeDiscoveryWithoutQuorum() {
    try (Cluster cluster = new Cluster(3)) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode clusterNode = cluster.getAnyNode();
        logger.debug("rebooting [{}]", clusterNode.getId());
        clusterNode.close();
        cluster.clusterNodes.forEach(cn -> cluster.deterministicTaskQueue.scheduleNow(cn.onNode(new Runnable() {

            @Override
            public void run() {
                cn.transportService.disconnectFromNode(clusterNode.getLocalNode());
            }

            @Override
            public String toString() {
                return "disconnect from " + clusterNode.getLocalNode() + " after shutdown";
            }
        })));
        IllegalStateException ise = expectThrows(IllegalStateException.class, () -> cluster.clusterNodes.replaceAll(cn -> cn == clusterNode ? cn.restartedNode(Function.identity(), Function.identity(), Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE).build()) : cn));
        assertThat(ise.getMessage(), allOf(containsString("cannot start with [discovery.type] set to [single-node] when local node"), containsString("does not have quorum in voting configuration")));
        // to avoid closing it twice
        cluster.clusterNodes.remove(clusterNode);
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) ElasticsearchException(org.elasticsearch.ElasticsearchException) LEADER_CHECK_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_TIMEOUT_SETTING) Arrays(java.util.Arrays) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) Matchers.not(org.hamcrest.Matchers.not) Level(org.apache.logging.log4j.Level) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) LogEvent(org.apache.logging.log4j.core.LogEvent) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) CANDIDATE(org.elasticsearch.cluster.coordination.Coordinator.Mode.CANDIDATE) DISCOVERY_FIND_PEERS_INTERVAL_SETTING(org.elasticsearch.discovery.PeerFinder.DISCOVERY_FIND_PEERS_INTERVAL_SETTING) Map(java.util.Map) Mode(org.elasticsearch.cluster.coordination.Coordinator.Mode) MockLogAppender(org.elasticsearch.test.MockLogAppender) FOLLOWER_CHECK_RETRY_COUNT_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_RETRY_COUNT_SETTING) LEADER_CHECK_INTERVAL_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_INTERVAL_SETTING) Set(java.util.Set) Collectors(java.util.stream.Collectors) Matchers.startsWith(org.hamcrest.Matchers.startsWith) AbstractDiffable(org.elasticsearch.cluster.AbstractDiffable) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Version(org.elasticsearch.Version) LEADER_CHECK_RETRY_COUNT_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_RETRY_COUNT_SETTING) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) NO_MASTER_BLOCK_ALL(org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_ALL) ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) PUBLISH_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.Coordinator.PUBLISH_TIMEOUT_SETTING) Matchers.containsString(org.hamcrest.Matchers.containsString) NO_MASTER_BLOCK_WRITES(org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_WRITES) DEFAULT_DELAY_VARIABILITY(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.DEFAULT_DELAY_VARIABILITY) AwaitsFix(org.apache.lucene.util.LuceneTestCase.AwaitsFix) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Function(java.util.function.Function) HashSet(java.util.HashSet) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) FOLLOWER_CHECK_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_TIMEOUT_SETTING) DiscoveryModule(org.elasticsearch.discovery.DiscoveryModule) Node(org.elasticsearch.node.Node) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Regex(org.elasticsearch.common.regex.Regex) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Loggers(org.elasticsearch.common.logging.Loggers) CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION(org.elasticsearch.cluster.coordination.Reconfigurator.CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION) IOException(java.io.IOException) ELECTION_INITIAL_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.ElectionSchedulerFactory.ELECTION_INITIAL_TIMEOUT_SETTING) FOLLOWER_CHECK_INTERVAL_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_INTERVAL_SETTING) Matchers.hasItem(org.hamcrest.Matchers.hasItem) GatewayService(org.elasticsearch.gateway.GatewayService) NO_MASTER_BLOCK_SETTING(org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_SETTING) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Builder(org.elasticsearch.common.settings.Settings.Builder) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 32 with Settings.builder

use of org.elasticsearch.common.settings.Settings.builder in project crate by crate.

the class InternalTestCluster method getRandomNodeSettings.

private static Settings getRandomNodeSettings(long seed) {
    Random random = new Random(seed);
    Builder builder = Settings.builder();
    builder.put(TransportSettings.TRANSPORT_COMPRESS.getKey(), rarely(random));
    if (random.nextBoolean()) {
        builder.put("cache.recycler.page.type", RandomPicks.randomFrom(random, PageCacheRecycler.Type.values()));
    }
    builder.put(EsExecutors.PROCESSORS_SETTING.getKey(), 1 + random.nextInt(3));
    // randomize tcp settings
    if (random.nextBoolean()) {
        builder.put(TransportSettings.CONNECTIONS_PER_NODE_RECOVERY.getKey(), random.nextInt(2) + 1);
        builder.put(TransportSettings.CONNECTIONS_PER_NODE_BULK.getKey(), random.nextInt(3) + 1);
        builder.put(TransportSettings.CONNECTIONS_PER_NODE_REG.getKey(), random.nextInt(6) + 1);
    }
    if (random.nextBoolean()) {
        builder.put(MappingUpdatedAction.INDICES_MAPPING_DYNAMIC_TIMEOUT_SETTING.getKey(), timeValueSeconds(RandomNumbers.randomIntBetween(random, 10, 30)).getStringRep());
    }
    if (random.nextInt(10) == 0) {
        builder.put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_TYPE_SETTING.getKey(), "noop");
    }
    if (random.nextBoolean()) {
        if (random.nextInt(10) == 0) {
            // do something crazy slow here
            builder.put(RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), new ByteSizeValue(RandomNumbers.randomIntBetween(random, 1, 10), ByteSizeUnit.MB));
        } else {
            builder.put(RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), new ByteSizeValue(RandomNumbers.randomIntBetween(random, 10, 200), ByteSizeUnit.MB));
        }
    }
    if (random.nextBoolean()) {
        builder.put(TransportSettings.PING_SCHEDULE.getKey(), RandomNumbers.randomIntBetween(random, 100, 2000) + "ms");
    }
    return builder.build();
}
Also used : Random(java.util.Random) Builder(org.elasticsearch.common.settings.Settings.Builder) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue)

Example 33 with Settings.builder

use of org.elasticsearch.common.settings.Settings.builder in project crate by crate.

the class InternalTestCluster method reset.

private synchronized void reset(boolean wipeData) throws IOException {
    // clear all rules for mock transport services
    for (NodeAndClient nodeAndClient : nodes.values()) {
        TransportService transportService = nodeAndClient.node.injector().getInstance(TransportService.class);
        if (transportService instanceof MockTransportService) {
            final MockTransportService mockTransportService = (MockTransportService) transportService;
            mockTransportService.clearAllRules();
        }
    }
    randomlyResetClients();
    final int newSize = sharedNodesSeeds.length;
    if (nextNodeId.get() == newSize && nodes.size() == newSize) {
        if (wipeData) {
            wipePendingDataDirectories();
        }
        logger.debug("Cluster hasn't changed - moving out - nodes: [{}] nextNodeId: [{}] numSharedNodes: [{}]", nodes.keySet(), nextNodeId.get(), newSize);
        return;
    }
    logger.debug("Cluster is NOT consistent - restarting shared nodes - nodes: [{}] nextNodeId: [{}] numSharedNodes: [{}]", nodes.keySet(), nextNodeId.get(), newSize);
    // trash all nodes with id >= sharedNodesSeeds.length - they are non shared
    final List<NodeAndClient> toClose = new ArrayList<>();
    for (NodeAndClient nodeAndClient : nodes.values()) {
        if (nodeAndClient.nodeAndClientId() >= sharedNodesSeeds.length) {
            logger.debug("Close Node [{}] not shared", nodeAndClient.name);
            toClose.add(nodeAndClient);
        }
    }
    stopNodesAndClients(toClose);
    // clean up what the nodes left that is unused
    if (wipeData) {
        wipePendingDataDirectories();
    }
    assertTrue("expected at least one master-eligible node left in " + nodes, nodes.isEmpty() || nodes.values().stream().anyMatch(NodeAndClient::isMasterEligible));
    final int prevNodeCount = nodes.size();
    // start any missing node
    assert newSize == numSharedDedicatedMasterNodes + numSharedDataNodes + numSharedCoordOnlyNodes;
    // we want to start nodes in one go
    final List<NodeAndClient> toStartAndPublish = new ArrayList<>();
    final Runnable onTransportServiceStarted = () -> rebuildUnicastHostFiles(toStartAndPublish);
    final List<Settings> settings = new ArrayList<>();
    for (int i = 0; i < numSharedDedicatedMasterNodes; i++) {
        final Settings.Builder extraSettings = Settings.builder();
        extraSettings.put(Node.NODE_MASTER_SETTING.getKey(), true);
        extraSettings.put(Node.NODE_DATA_SETTING.getKey(), false);
        settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build()));
    }
    for (int i = numSharedDedicatedMasterNodes; i < numSharedDedicatedMasterNodes + numSharedDataNodes; i++) {
        final Settings.Builder extraSettings = Settings.builder();
        if (numSharedDedicatedMasterNodes > 0) {
            // if we don't have dedicated master nodes, keep things default
            extraSettings.put(Node.NODE_MASTER_SETTING.getKey(), false).build();
            extraSettings.put(Node.NODE_DATA_SETTING.getKey(), true).build();
        }
        settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build()));
    }
    for (int i = numSharedDedicatedMasterNodes + numSharedDataNodes; i < numSharedDedicatedMasterNodes + numSharedDataNodes + numSharedCoordOnlyNodes; i++) {
        final Builder extraSettings = Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false).put(Node.NODE_DATA_SETTING.getKey(), false);
        settings.add(getNodeSettings(i, sharedNodesSeeds[i], extraSettings.build()));
    }
    int autoBootstrapMasterNodeIndex = -1;
    final List<String> masterNodeNames = settings.stream().filter(Node.NODE_MASTER_SETTING::get).map(Node.NODE_NAME_SETTING::get).collect(Collectors.toList());
    if (prevNodeCount == 0 && autoManageMasterNodes) {
        if (numSharedDedicatedMasterNodes > 0) {
            autoBootstrapMasterNodeIndex = RandomNumbers.randomIntBetween(random, 0, numSharedDedicatedMasterNodes - 1);
        } else if (numSharedDataNodes > 0) {
            autoBootstrapMasterNodeIndex = RandomNumbers.randomIntBetween(random, 0, numSharedDataNodes - 1);
        }
    }
    final List<Settings> updatedSettings = bootstrapMasterNodeWithSpecifiedIndex(settings);
    for (int i = 0; i < numSharedDedicatedMasterNodes + numSharedDataNodes + numSharedCoordOnlyNodes; i++) {
        Settings nodeSettings = updatedSettings.get(i);
        if (i == autoBootstrapMasterNodeIndex) {
            nodeSettings = Settings.builder().putList(INITIAL_MASTER_NODES_SETTING.getKey(), masterNodeNames).put(nodeSettings).build();
        }
        final NodeAndClient nodeAndClient = buildNode(i, nodeSettings, true, onTransportServiceStarted);
        toStartAndPublish.add(nodeAndClient);
    }
    startAndPublishNodesAndClients(toStartAndPublish);
    nextNodeId.set(newSize);
    assert size() == newSize;
    if (autoManageMasterNodes && newSize > 0) {
        validateClusterFormed();
    }
    logger.debug("Cluster is consistent again - nodes: [{}] nextNodeId: [{}] numSharedNodes: [{}]", nodes.keySet(), nextNodeId.get(), newSize);
}
Also used : MockTransportService(org.elasticsearch.test.transport.MockTransportService) Builder(org.elasticsearch.common.settings.Settings.Builder) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Node(org.elasticsearch.node.Node) MockNode(org.elasticsearch.node.MockNode) ArrayList(java.util.ArrayList) Builder(org.elasticsearch.common.settings.Settings.Builder) TransportService(org.elasticsearch.transport.TransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) RecoverySettings(org.elasticsearch.indices.recovery.RecoverySettings) TransportSettings(org.elasticsearch.transport.TransportSettings) DiskThresholdSettings(org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 34 with Settings.builder

use of org.elasticsearch.common.settings.Settings.builder in project crate by crate.

the class ReconfiguratorTests method testAutoShrinking.

public void testAutoShrinking() {
    final String[] allNodes = new String[] { "a", "b", "c", "d", "e", "f", "g" };
    final String[] liveNodes = new String[randomIntBetween(1, allNodes.length)];
    randomSubsetOf(liveNodes.length, allNodes).toArray(liveNodes);
    final String[] initialVotingNodes = new String[randomIntBetween(1, allNodes.length)];
    randomSubsetOf(initialVotingNodes.length, allNodes).toArray(initialVotingNodes);
    final Builder settingsBuilder = Settings.builder();
    if (randomBoolean()) {
        settingsBuilder.put(CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION.getKey(), true);
    }
    final Reconfigurator reconfigurator = makeReconfigurator(settingsBuilder.build());
    final Set<DiscoveryNode> liveNodesSet = nodes(liveNodes);
    final VotingConfiguration initialConfig = conf(initialVotingNodes);
    final int quorumSize = Math.max(liveNodes.length / 2 + 1, initialVotingNodes.length < 3 ? 1 : 2);
    final VotingConfiguration finalConfig = reconfigurator.reconfigure(liveNodesSet, emptySet(), randomFrom(liveNodesSet), initialConfig);
    final String description = "reconfigure " + liveNodesSet + " from " + initialConfig + " yielded " + finalConfig;
    if (quorumSize > liveNodes.length) {
        assertFalse(description + " without a live quorum", finalConfig.hasQuorum(Arrays.asList(liveNodes)));
    } else {
        final List<String> expectedQuorum = randomSubsetOf(quorumSize, liveNodes);
        assertTrue(description + " with quorum[" + quorumSize + "] of " + expectedQuorum, finalConfig.hasQuorum(expectedQuorum));
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Builder(org.elasticsearch.common.settings.Settings.Builder) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Aggregations

Builder (org.elasticsearch.common.settings.Settings.Builder)34 Settings (org.elasticsearch.common.settings.Settings)16 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)16 XContentFactory.jsonBuilder (org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder)10 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)8 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)8 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)8 DiskThresholdSettings (org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings)7 RecoverySettings (org.elasticsearch.indices.recovery.RecoverySettings)7 TransportSettings (org.elasticsearch.transport.TransportSettings)7 SearchResponse (org.elasticsearch.action.search.SearchResponse)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)5 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)5 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)5 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)5 ArrayList (java.util.ArrayList)4 TransportClient (org.elasticsearch.client.transport.TransportClient)4 QueryRescorerBuilder (org.elasticsearch.search.rescore.QueryRescorerBuilder)4 RescoreBuilder (org.elasticsearch.search.rescore.RescoreBuilder)4 UnknownHostException (java.net.UnknownHostException)3