use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandleCommitWithBadLastAcceptedTerm.
public void testHandleCommitWithBadLastAcceptedTerm() {
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());
assertThat(expectThrows(CoordinationStateRejectedException.class, () -> cs1.handleCommit(new ApplyCommitRequest(node1, startJoinRequest1.getTerm(), 2L))).getMessage(), containsString("does not match last accepted term"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandleClientValue.
public void testHandleClientValue() {
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);
Join v2 = cs2.handleStartJoin(startJoinRequest1);
assertTrue(cs1.handleJoin(v1));
assertTrue(cs1.electionWon());
assertTrue(cs1.handleJoin(v2));
VotingConfiguration newConfig = new VotingConfiguration(Collections.singleton(node2.getId()));
ClusterState state2 = clusterState(startJoinRequest1.getTerm(), 2L, node1, initialConfig, newConfig, 42L);
PublishRequest publishRequest = cs1.handleClientValue(state2);
assertThat(publishRequest.getAcceptedState(), equalTo(state2));
assertThat(cs1.getLastPublishedVersion(), equalTo(state2.version()));
// check that another join does not mess with lastPublishedVersion
Join v3 = cs3.handleStartJoin(startJoinRequest1);
assertTrue(cs1.handleJoin(v3));
assertThat(cs1.getLastPublishedVersion(), equalTo(state2.version()));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationStateTests method testHandlePublishRequest.
public void testHandlePublishRequest() {
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);
if (randomBoolean()) {
assertTrue(cs1.handleJoin(v1));
assertTrue(cs1.electionWon());
}
ClusterState state2 = clusterState(startJoinRequest1.getTerm(), randomLongBetween(1, 10), node1, initialConfig, initialConfig, 13L);
PublishResponse publishResponse = cs1.handlePublishRequest(new PublishRequest(state2));
assertThat(publishResponse.getTerm(), equalTo(state2.term()));
assertThat(publishResponse.getVersion(), equalTo(state2.version()));
assertThat(cs1.getLastAcceptedState(), equalTo(state2));
assertThat(value(cs1.getLastAcceptedState()), equalTo(13L));
ClusterState state3 = clusterState(startJoinRequest1.getTerm(), randomLongBetween(state2.getVersion() + 1, 20), node1, initialConfig, initialConfig, 13L);
cs1.handlePublishRequest(new PublishRequest(state3));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class PublicationTests method testClusterStatePublishingWithFaultyNodeBeforeCommit.
public void testClusterStatePublishingWithFaultyNodeBeforeCommit() throws InterruptedException {
VotingConfiguration singleNodeConfig = new VotingConfiguration(Set.of(n1.getId()));
initializeCluster(singleNodeConfig);
AssertingAckListener ackListener = new AssertingAckListener(nodes.size());
DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().add(n1).add(n2).add(n3).localNodeId(n1.getId()).build();
// number of publish actions + initial faulty nodes injection
AtomicInteger remainingActions = new AtomicInteger(4);
int injectFaultAt = randomInt(remainingActions.get() - 1);
logger.info("Injecting fault at: {}", injectFaultAt);
Set<DiscoveryNode> initialFaultyNodes = remainingActions.decrementAndGet() == injectFaultAt ? Collections.singleton(n2) : Collections.emptySet();
MockPublication publication = node1.publish(CoordinationStateTests.clusterState(1L, 2L, discoveryNodes, singleNodeConfig, singleNodeConfig, 42L), ackListener, initialFaultyNodes);
publication.pendingPublications.entrySet().stream().collect(shuffle()).forEach(e -> {
if (remainingActions.decrementAndGet() == injectFaultAt) {
publication.onFaultyNode(n2);
}
if (e.getKey().equals(n2) == false || randomBoolean()) {
PublishResponse publishResponse = nodeResolver.apply(e.getKey()).coordinationState.handlePublishRequest(publication.publishRequest);
e.getValue().onResponse(new PublishWithJoinResponse(publishResponse, Optional.empty()));
}
});
publication.pendingCommits.entrySet().stream().collect(shuffle()).forEach(e -> {
nodeResolver.apply(e.getKey()).coordinationState.handleCommit(publication.applyCommit);
e.getValue().onResponse(TransportResponse.Empty.INSTANCE);
});
assertTrue(publication.completed);
assertTrue(publication.committed);
// has no influence
publication.onFaultyNode(randomFrom(n1, n3));
List<Tuple<DiscoveryNode, Throwable>> errors = ackListener.awaitErrors(0L, TimeUnit.SECONDS);
assertThat(errors.size(), equalTo(1));
assertThat(errors.get(0).v1(), equalTo(n2));
assertThat(errors.get(0).v2().getMessage(), containsString("faulty node"));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class PublicationTests method testClusterStatePublishingWithFaultyNodeAfterCommit.
public void testClusterStatePublishingWithFaultyNodeAfterCommit() throws InterruptedException {
VotingConfiguration singleNodeConfig = new VotingConfiguration(Set.of(n1.getId()));
initializeCluster(singleNodeConfig);
AssertingAckListener ackListener = new AssertingAckListener(nodes.size());
DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().add(n1).add(n2).add(n3).localNodeId(n1.getId()).build();
boolean publicationDidNotMakeItToNode2 = randomBoolean();
AtomicInteger remainingActions = new AtomicInteger(publicationDidNotMakeItToNode2 ? 2 : 3);
int injectFaultAt = randomInt(remainingActions.get() - 1);
logger.info("Injecting fault at: {}, publicationDidNotMakeItToNode2: {}", injectFaultAt, publicationDidNotMakeItToNode2);
MockPublication publication = node1.publish(CoordinationStateTests.clusterState(1L, 2L, discoveryNodes, singleNodeConfig, singleNodeConfig, 42L), ackListener, Collections.emptySet());
publication.pendingPublications.entrySet().stream().collect(shuffle()).forEach(e -> {
if (e.getKey().equals(n2) == false || publicationDidNotMakeItToNode2 == false) {
PublishResponse publishResponse = nodeResolver.apply(e.getKey()).coordinationState.handlePublishRequest(publication.publishRequest);
e.getValue().onResponse(new PublishWithJoinResponse(publishResponse, Optional.empty()));
}
});
publication.pendingCommits.entrySet().stream().collect(shuffle()).forEach(e -> {
if (e.getKey().equals(n2)) {
// we must fail node before committing for the node, otherwise failing the node is ignored
publication.onFaultyNode(n2);
}
if (remainingActions.decrementAndGet() == injectFaultAt) {
publication.onFaultyNode(n2);
}
if (e.getKey().equals(n2) == false || randomBoolean()) {
nodeResolver.apply(e.getKey()).coordinationState.handleCommit(publication.applyCommit);
e.getValue().onResponse(TransportResponse.Empty.INSTANCE);
}
});
// we need to complete publication by failing the node
if (publicationDidNotMakeItToNode2 && remainingActions.get() > injectFaultAt) {
publication.onFaultyNode(n2);
}
assertTrue(publication.completed);
assertTrue(publication.committed);
// has no influence
publication.onFaultyNode(randomFrom(n1, n3));
List<Tuple<DiscoveryNode, Throwable>> errors = ackListener.awaitErrors(0L, TimeUnit.SECONDS);
assertThat(errors.size(), equalTo(1));
assertThat(errors.get(0).v1(), equalTo(n2));
assertThat(errors.get(0).v2().getMessage(), containsString("faulty node"));
}
Aggregations