Search in sources :

Example 26 with VotingConfiguration

use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.

the class PublicationTests method testClusterStatePublishingTimesOutAfterCommit.

public void testClusterStatePublishingTimesOutAfterCommit() throws InterruptedException {
    VotingConfiguration config = new VotingConfiguration(randomBoolean() ? Set.of(n1.getId(), n2.getId()) : Set.of(n1.getId(), n2.getId(), n3.getId()));
    initializeCluster(config);
    AssertingAckListener ackListener = new AssertingAckListener(nodes.size());
    DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().add(n1).add(n2).add(n3).localNodeId(n1.getId()).build();
    MockPublication publication = node1.publish(CoordinationStateTests.clusterState(1L, 2L, discoveryNodes, config, config, 42L), ackListener, Collections.emptySet());
    boolean publishedToN3 = randomBoolean();
    publication.pendingPublications.entrySet().stream().collect(shuffle()).forEach(e -> {
        if (e.getKey().equals(n3) == false || publishedToN3) {
            PublishResponse publishResponse = nodeResolver.apply(e.getKey()).coordinationState.handlePublishRequest(publication.publishRequest);
            e.getValue().onResponse(new PublishWithJoinResponse(publishResponse, Optional.empty()));
        }
    });
    assertNotNull(publication.applyCommit);
    Set<DiscoveryNode> committingNodes = new HashSet<>(randomSubsetOf(discoNodes));
    if (publishedToN3 == false) {
        committingNodes.remove(n3);
    }
    logger.info("Committing nodes: {}", committingNodes);
    publication.pendingCommits.entrySet().stream().collect(shuffle()).forEach(e -> {
        if (committingNodes.contains(e.getKey())) {
            nodeResolver.apply(e.getKey()).coordinationState.handleCommit(publication.applyCommit);
            e.getValue().onResponse(TransportResponse.Empty.INSTANCE);
        }
    });
    publication.cancel("timed out");
    assertTrue(publication.completed);
    assertTrue(publication.committed);
    assertEquals(committingNodes, ackListener.await(0L, TimeUnit.SECONDS));
    // check that acking still works after publication completed
    if (publishedToN3 == false) {
        publication.pendingPublications.get(n3).onResponse(new PublishWithJoinResponse(node3.coordinationState.handlePublishRequest(publication.publishRequest), Optional.empty()));
    }
    assertEquals(discoNodes, publication.pendingCommits.keySet());
    Set<DiscoveryNode> nonCommittedNodes = Sets.difference(discoNodes, committingNodes);
    logger.info("Non-committed nodes: {}", nonCommittedNodes);
    nonCommittedNodes.stream().collect(shuffle()).forEach(n -> publication.pendingCommits.get(n).onResponse(TransportResponse.Empty.INSTANCE));
    assertEquals(discoNodes, ackListener.await(0L, TimeUnit.SECONDS));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) HashSet(java.util.HashSet)

Example 27 with VotingConfiguration

use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.

the class ReconfiguratorTests method check.

private void check(Set<DiscoveryNode> liveNodes, Set<String> retired, String masterId, VotingConfiguration config, boolean autoShrinkVotingConfiguration, VotingConfiguration expectedConfig) {
    final Reconfigurator reconfigurator = makeReconfigurator(Settings.builder().put(CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION.getKey(), autoShrinkVotingConfiguration).build());
    final DiscoveryNode master = liveNodes.stream().filter(n -> n.getId().equals(masterId)).findFirst().get();
    final VotingConfiguration adaptedConfig = reconfigurator.reconfigure(liveNodes, retired, master, config);
    assertEquals(new ParameterizedMessage("[liveNodes={}, retired={}, master={}, config={}, autoShrinkVotingConfiguration={}]", liveNodes, retired, master, config, autoShrinkVotingConfiguration).getFormattedMessage(), expectedConfig, adaptedConfig);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 28 with VotingConfiguration

use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.

the class ReconfiguratorTests method testDynamicSetting.

public void testDynamicSetting() {
    final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    final Reconfigurator reconfigurator = new Reconfigurator(Settings.EMPTY, clusterSettings);
    final VotingConfiguration initialConfig = conf("a", "b", "c", "d", "e");
    Set<DiscoveryNode> twoNodes = nodes("a", "b");
    Set<DiscoveryNode> threeNodes = nodes("a", "b", "c");
    // default is "true"
    assertThat(reconfigurator.reconfigure(twoNodes, retired(), randomFrom(twoNodes), initialConfig), equalTo(conf("a", "b", "c")));
    // update to "false"
    clusterSettings.applySettings(Settings.builder().put(CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION.getKey(), "false").build());
    assertThat(reconfigurator.reconfigure(twoNodes, retired(), randomFrom(twoNodes), initialConfig), // no quorum
    sameInstance(initialConfig));
    assertThat(reconfigurator.reconfigure(threeNodes, retired(), randomFrom(threeNodes), initialConfig), equalTo(conf("a", "b", "c", "d", "e")));
    assertThat(reconfigurator.reconfigure(threeNodes, retired("d"), randomFrom(threeNodes), initialConfig), equalTo(conf("a", "b", "c", "e")));
    // explicitly set to "true"
    clusterSettings.applySettings(Settings.builder().put(CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION.getKey(), "true").build());
    assertThat(reconfigurator.reconfigure(twoNodes, retired(), randomFrom(twoNodes), initialConfig), equalTo(conf("a", "b", "c")));
    expectThrows(IllegalArgumentException.class, () -> clusterSettings.applySettings(Settings.builder().put(CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION.getKey(), "blah").build()));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 29 with VotingConfiguration

use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.

the class ReconfiguratorTests method testManualShrinking.

public void testManualShrinking() {
    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 Reconfigurator reconfigurator = makeReconfigurator(Settings.builder().put(CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION.getKey(), false).build());
    final Set<DiscoveryNode> liveNodesSet = nodes(liveNodes);
    final VotingConfiguration initialConfig = conf(initialVotingNodes);
    final int quorumSize = Math.max(liveNodes.length, initialVotingNodes.length) / 2 + 1;
    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) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 30 with VotingConfiguration

use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.

the class NodeJoinTests method testJoinFollowerWithHigherTerm.

public void testJoinFollowerWithHigherTerm() throws Exception {
    DiscoveryNode node0 = newNode(0, true);
    DiscoveryNode node1 = newNode(1, true);
    long initialTerm = randomLongBetween(1, 10);
    long initialVersion = randomLongBetween(1, 10);
    setupFakeMasterServiceAndCoordinator(initialTerm, initialState(node0, initialTerm, initialVersion, new VotingConfiguration(Collections.singleton(node0.getId()))));
    long newTerm = initialTerm + randomLongBetween(1, 10);
    handleStartJoinFrom(node1, newTerm);
    handleFollowerCheckFrom(node1, newTerm);
    long newerTerm = newTerm + randomLongBetween(1, 10);
    joinNodeAndRun(new JoinRequest(node1, Optional.of(new Join(node1, node0, newerTerm, initialTerm, initialVersion))));
    assertTrue(isLocalNodeElectedMaster());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Aggregations

VotingConfiguration (org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)66 ClusterState (org.elasticsearch.cluster.ClusterState)40 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)19 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)8 Set (java.util.Set)6 HashSet (java.util.HashSet)5 Settings (org.elasticsearch.common.settings.Settings)5 Tuple (io.crate.common.collections.Tuple)4 Collections (java.util.Collections)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Collectors (java.util.stream.Collectors)4 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)4 TimeValue (io.crate.common.unit.TimeValue)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Optional (java.util.Optional)3 TimeUnit (java.util.concurrent.TimeUnit)3 Stream (java.util.stream.Stream)3 ESTestCase (org.elasticsearch.test.ESTestCase)3