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);
}
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"));
}
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"));
}
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"));
}
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));
}
Aggregations