Search in sources :

Example 51 with VotingConfiguration

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

the class PublicationTests method testPublishingToMastersFirst.

public void testPublishingToMastersFirst() {
    VotingConfiguration singleNodeConfig = new VotingConfiguration(Set.of(n1.getId()));
    initializeCluster(singleNodeConfig);
    DiscoveryNodes.Builder discoNodesBuilder = DiscoveryNodes.builder();
    randomNodes(10).forEach(dn -> discoNodesBuilder.add(dn));
    DiscoveryNodes discoveryNodes = discoNodesBuilder.add(n1).localNodeId(n1.getId()).build();
    MockPublication publication = node1.publish(CoordinationStateTests.clusterState(1L, 2L, discoveryNodes, singleNodeConfig, singleNodeConfig, 42L), null, Collections.emptySet());
    List<DiscoveryNode> publicationTargets = new ArrayList<>(publication.pendingPublications.keySet());
    List<DiscoveryNode> sortedPublicationTargets = new ArrayList<>(publicationTargets);
    Collections.sort(sortedPublicationTargets, Comparator.comparing(n -> n.isMasterEligibleNode() == false));
    assertEquals(sortedPublicationTargets, publicationTargets);
}
Also used : Arrays(java.util.Arrays) Tuple(io.crate.common.collections.Tuple) LongSupplier(java.util.function.LongSupplier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Sets(io.crate.common.collections.Sets) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) TransportResponse(org.elasticsearch.transport.TransportResponse) ESTestCase(org.elasticsearch.test.ESTestCase) Collector(java.util.stream.Collector) Nullable(javax.annotation.Nullable) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Matchers.empty(org.hamcrest.Matchers.empty) Discovery(org.elasticsearch.discovery.Discovery) Set(java.util.Set) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) Version(org.elasticsearch.Version) Stream(java.util.stream.Stream) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TimeValue(io.crate.common.unit.TimeValue) Optional(java.util.Optional) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) Comparator(java.util.Comparator) TransportException(org.elasticsearch.transport.TransportException) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) ActionListener(org.elasticsearch.action.ActionListener) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 52 with VotingConfiguration

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

the class CoordinationStateTests method testJoinWithHigherAcceptedTerm.

public void testJoinWithHigherAcceptedTerm() {
    VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
    ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
    cs1.setInitialState(state1);
    StartJoinRequest startJoinRequest1 = new StartJoinRequest(node2, randomLongBetween(1, 5));
    cs1.handleStartJoin(startJoinRequest1);
    ClusterState state2 = clusterState(startJoinRequest1.getTerm(), randomLongBetween(2, 20), node1, initialConfig, initialConfig, 42L);
    cs1.handlePublishRequest(new PublishRequest(state2));
    StartJoinRequest startJoinRequest2 = new StartJoinRequest(node2, randomLongBetween(startJoinRequest1.getTerm() + 1, 10));
    Join v1 = cs1.handleStartJoin(startJoinRequest2);
    Join badJoin = new Join(randomFrom(node1, node2), node1, v1.getTerm(), randomLongBetween(state2.term() + 1, 30), randomNonNegativeLong());
    assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handleJoin(badJoin)).getMessage(), containsString("higher than current last accepted term"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 53 with VotingConfiguration

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

the class CoordinationStateTests method testStartJoinAfterBootstrap.

public void testStartJoinAfterBootstrap() {
    VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
    ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
    assertTrue(state1.getLastAcceptedConfiguration().hasQuorum(Collections.singleton(node1.getId())));
    assertTrue(state1.getLastCommittedConfiguration().hasQuorum(Collections.singleton(node1.getId())));
    cs1.setInitialState(state1);
    StartJoinRequest startJoinRequest1 = new StartJoinRequest(randomFrom(node1, node2), randomLongBetween(1, 5));
    Join v1 = cs1.handleStartJoin(startJoinRequest1);
    assertThat(v1.getTargetNode(), equalTo(startJoinRequest1.getSourceNode()));
    assertThat(v1.getSourceNode(), equalTo(node1));
    assertThat(v1.getTerm(), equalTo(startJoinRequest1.getTerm()));
    assertThat(v1.getLastAcceptedTerm(), equalTo(state1.term()));
    assertThat(v1.getLastAcceptedVersion(), equalTo(state1.version()));
    assertThat(cs1.getCurrentTerm(), equalTo(startJoinRequest1.getTerm()));
    StartJoinRequest startJoinRequest2 = new StartJoinRequest(randomFrom(node1, node2), randomLongBetween(0, startJoinRequest1.getTerm()));
    assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handleStartJoin(startJoinRequest2)).getMessage(), containsString("not greater than current term"));
    StartJoinRequest startJoinRequest3 = new StartJoinRequest(randomFrom(node1, node2), startJoinRequest1.getTerm());
    assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handleStartJoin(startJoinRequest3)).getMessage(), containsString("not greater than current term"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 54 with VotingConfiguration

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

the class CoordinationStateTests method testHandleClientValueDuringOngoingPublication.

public void testHandleClientValueDuringOngoingPublication() {
    VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
    ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
    cs1.setInitialState(state1);
    StartJoinRequest startJoinRequest1 = new StartJoinRequest(node1, randomLongBetween(1, 5));
    Join v1 = cs1.handleStartJoin(startJoinRequest1);
    assertTrue(cs1.handleJoin(v1));
    assertTrue(cs1.electionWon());
    ClusterState state2 = clusterState(startJoinRequest1.getTerm(), 2L, node1, initialConfig, initialConfig, 42L);
    cs1.handleClientValue(state2);
    ClusterState state3 = clusterState(startJoinRequest1.getTerm(), 3L, node1, initialConfig, initialConfig, 42L);
    assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handleClientValue(state3)).getMessage(), containsString("cannot start publishing next value before accepting previous one"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 55 with VotingConfiguration

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

the class CoordinationStateTests method testJoinWithLowerLastAcceptedTermWinsElection.

public void testJoinWithLowerLastAcceptedTermWinsElection() {
    VotingConfiguration initialConfig = new VotingConfiguration(Collections.singleton(node1.getId()));
    ClusterState state1 = clusterState(0L, 0L, node1, initialConfig, initialConfig, 42L);
    cs1.setInitialState(state1);
    StartJoinRequest startJoinRequest1 = new StartJoinRequest(node2, randomLongBetween(1, 5));
    cs1.handleStartJoin(startJoinRequest1);
    ClusterState state2 = clusterState(startJoinRequest1.getTerm(), randomLongBetween(2, 20), node1, initialConfig, initialConfig, 42L);
    cs1.handlePublishRequest(new PublishRequest(state2));
    StartJoinRequest startJoinRequest2 = new StartJoinRequest(node2, randomLongBetween(startJoinRequest1.getTerm() + 1, 10));
    Join v1 = cs1.handleStartJoin(startJoinRequest2);
    Join join = new Join(node1, node1, v1.getTerm(), randomLongBetween(0, state2.term() - 1), randomLongBetween(0, 20));
    assertTrue(cs1.handleJoin(join));
    assertTrue(cs1.electionWon());
    assertTrue(cs1.containsJoinVoteFor(node1));
    assertFalse(cs1.containsJoinVoteFor(node2));
    assertEquals(cs1.getLastPublishedVersion(), cs1.getLastAcceptedVersion());
    assertFalse(cs1.handleJoin(join));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) 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