use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration 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));
}
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationMetadataTests method testVotingConfiguration.
public void testVotingConfiguration() {
VotingConfiguration config0 = new VotingConfiguration(Set.of());
assertThat(config0, equalTo(VotingConfiguration.EMPTY_CONFIG));
assertThat(config0.getNodeIds(), equalTo(Set.of()));
assertThat(config0.isEmpty(), equalTo(true));
assertThat(config0.hasQuorum(Set.of()), equalTo(false));
assertThat(config0.hasQuorum(Set.of("id1")), equalTo(false));
VotingConfiguration config1 = new VotingConfiguration(Set.of("id1"));
assertThat(config1.getNodeIds(), equalTo(Set.of("id1")));
assertThat(config1.isEmpty(), equalTo(false));
assertThat(config1.hasQuorum(Set.of("id1")), equalTo(true));
assertThat(config1.hasQuorum(Set.of("id1", "id2")), equalTo(true));
assertThat(config1.hasQuorum(Set.of("id2")), equalTo(false));
assertThat(config1.hasQuorum(Set.of()), equalTo(false));
VotingConfiguration config2 = new VotingConfiguration(Set.of("id1", "id2"));
assertThat(config2.getNodeIds(), equalTo(Set.of("id1", "id2")));
assertThat(config2.isEmpty(), equalTo(false));
assertThat(config2.hasQuorum(Set.of("id1", "id2")), equalTo(true));
assertThat(config2.hasQuorum(Set.of("id1", "id2", "id3")), equalTo(true));
assertThat(config2.hasQuorum(Set.of("id1")), equalTo(false));
assertThat(config2.hasQuorum(Set.of("id2")), equalTo(false));
assertThat(config2.hasQuorum(Set.of("id3")), equalTo(false));
assertThat(config2.hasQuorum(Set.of("id1", "id3")), equalTo(false));
assertThat(config2.hasQuorum(Set.of()), equalTo(false));
VotingConfiguration config3 = new VotingConfiguration(Set.of("id1", "id2", "id3"));
assertThat(config3.getNodeIds(), equalTo(Set.of("id1", "id2", "id3")));
assertThat(config3.isEmpty(), equalTo(false));
assertThat(config3.hasQuorum(Set.of("id1", "id2")), equalTo(true));
assertThat(config3.hasQuorum(Set.of("id2", "id3")), equalTo(true));
assertThat(config3.hasQuorum(Set.of("id1", "id3")), equalTo(true));
assertThat(config3.hasQuorum(Set.of("id1", "id2", "id3")), equalTo(true));
assertThat(config3.hasQuorum(Set.of("id1", "id2", "id4")), equalTo(true));
assertThat(config3.hasQuorum(Set.of("id1")), equalTo(false));
assertThat(config3.hasQuorum(Set.of("id2")), equalTo(false));
assertThat(config3.hasQuorum(Set.of("id3")), equalTo(false));
assertThat(config3.hasQuorum(Set.of("id1", "id4")), equalTo(false));
assertThat(config3.hasQuorum(Set.of("id1", "id4", "id5")), equalTo(false));
assertThat(config3.hasQuorum(Set.of()), equalTo(false));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class CoordinationMetadataTests method testVotingConfigurationSerializationEqualsHashCode.
public void testVotingConfigurationSerializationEqualsHashCode() {
VotingConfiguration initialConfig = randomVotingConfig();
// Note: the explicit cast of the CopyFunction is needed for some IDE (specifically Eclipse 4.8.0) to infer the right type
EqualsHashCodeTestUtils.checkEqualsAndHashCode(initialConfig, (CopyFunction<VotingConfiguration>) orig -> ESTestCase.copyWriteable(orig, new NamedWriteableRegistry(Collections.emptyList()), VotingConfiguration::new), cfg -> randomlyChangeVotingConfiguration(cfg));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class PublicationTests method testClusterStatePublishingFailsOrTimesOutBeforeCommit.
public void testClusterStatePublishingFailsOrTimesOutBeforeCommit() throws InterruptedException {
VotingConfiguration config = new VotingConfiguration(Set.of(n1.getId(), n2.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 timeOut = randomBoolean();
publication.pendingPublications.entrySet().stream().collect(shuffle()).forEach(e -> {
if (e.getKey().equals(n2)) {
if (timeOut) {
publication.cancel("timed out");
} else {
e.getValue().onFailure(new TransportException(new Exception("dummy failure")));
}
assertTrue(publication.completed);
assertFalse(publication.committed);
} else if (randomBoolean()) {
PublishResponse publishResponse = nodeResolver.apply(e.getKey()).coordinationState.handlePublishRequest(publication.publishRequest);
e.getValue().onResponse(new PublishWithJoinResponse(publishResponse, Optional.empty()));
}
});
assertThat(publication.pendingCommits.keySet(), equalTo(Collections.emptySet()));
assertNull(publication.applyCommit);
assertTrue(publication.completed);
assertFalse(publication.committed);
List<Tuple<DiscoveryNode, Throwable>> errors = ackListener.awaitErrors(0L, TimeUnit.SECONDS);
assertThat(errors.size(), equalTo(3));
assertThat(errors.stream().map(Tuple::v1).collect(Collectors.toList()), containsInAnyOrder(n1, n2, n3));
errors.stream().forEach(tuple -> assertThat(tuple.v2().getMessage(), containsString(timeOut ? "timed out" : tuple.v1().equals(n2) ? "dummy failure" : "non-failed nodes do not form a quorum")));
}
use of org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration in project crate by crate.
the class PublicationTests method testSimpleClusterStatePublishing.
public void testSimpleClusterStatePublishing() 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();
MockPublication publication = node1.publish(CoordinationStateTests.clusterState(1L, 2L, discoveryNodes, singleNodeConfig, singleNodeConfig, 42L), ackListener, Collections.emptySet());
assertThat(publication.pendingPublications.keySet(), equalTo(discoNodes));
assertThat(publication.completedNodes(), empty());
assertTrue(publication.pendingCommits.isEmpty());
AtomicBoolean processedNode1PublishResponse = new AtomicBoolean();
boolean delayProcessingNode2PublishResponse = randomBoolean();
publication.pendingPublications.entrySet().stream().collect(shuffle()).forEach(e -> {
if (delayProcessingNode2PublishResponse && e.getKey().equals(n2)) {
return;
}
PublishResponse publishResponse = nodeResolver.apply(e.getKey()).coordinationState.handlePublishRequest(publication.publishRequest);
assertNotEquals(processedNode1PublishResponse.get(), publication.pendingCommits.isEmpty());
assertFalse(publication.joins.containsKey(e.getKey()));
PublishWithJoinResponse publishWithJoinResponse = new PublishWithJoinResponse(publishResponse, randomBoolean() ? Optional.empty() : Optional.of(new Join(e.getKey(), randomFrom(n1, n2, n3), publishResponse.getTerm(), randomNonNegativeLong(), randomNonNegativeLong())));
e.getValue().onResponse(publishWithJoinResponse);
if (publishWithJoinResponse.getJoin().isPresent()) {
assertTrue(publication.joins.containsKey(e.getKey()));
assertFalse(publication.missingJoins.contains(e.getKey()));
assertEquals(publishWithJoinResponse.getJoin().get(), publication.joins.get(e.getKey()));
} else {
assertFalse(publication.joins.containsKey(e.getKey()));
assertTrue(publication.missingJoins.contains(e.getKey()));
}
if (e.getKey().equals(n1)) {
processedNode1PublishResponse.set(true);
}
assertNotEquals(processedNode1PublishResponse.get(), publication.pendingCommits.isEmpty());
});
if (delayProcessingNode2PublishResponse) {
assertThat(publication.pendingCommits.keySet(), equalTo(Set.of(n1, n3)));
} else {
assertThat(publication.pendingCommits.keySet(), equalTo(discoNodes));
}
assertNotNull(publication.applyCommit);
assertEquals(publication.applyCommit.getTerm(), publication.publishRequest.getAcceptedState().term());
assertEquals(publication.applyCommit.getVersion(), publication.publishRequest.getAcceptedState().version());
publication.pendingCommits.entrySet().stream().collect(shuffle()).forEach(e -> {
assertFalse(publication.completed);
assertFalse(publication.committed);
nodeResolver.apply(e.getKey()).coordinationState.handleCommit(publication.applyCommit);
e.getValue().onResponse(TransportResponse.Empty.INSTANCE);
});
if (delayProcessingNode2PublishResponse) {
assertFalse(publication.completed);
assertFalse(publication.committed);
PublishResponse publishResponse = nodeResolver.apply(n2).coordinationState.handlePublishRequest(publication.publishRequest);
publication.pendingPublications.get(n2).onResponse(new PublishWithJoinResponse(publishResponse, Optional.empty()));
assertThat(publication.pendingCommits.keySet(), equalTo(discoNodes));
assertFalse(publication.completed);
assertFalse(publication.committed);
assertThat(publication.completedNodes(), containsInAnyOrder(n1, n3));
publication.pendingCommits.get(n2).onResponse(TransportResponse.Empty.INSTANCE);
}
assertTrue(publication.completed);
assertThat(publication.completedNodes(), containsInAnyOrder(n1, n2, n3));
assertTrue(publication.committed);
assertThat(ackListener.await(0L, TimeUnit.SECONDS), containsInAnyOrder(n1, n2, n3));
}
Aggregations