Search in sources :

Example 26 with ClusterNode

use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.

the class CoordinatorTests method testStayCandidateAfterReceivingFollowerCheckFromKnownMaster.

/**
 * Simulates a situation where a follower becomes disconnected from the leader, but only for such a short time where
 * it becomes candidate and puts up a NO_MASTER_BLOCK, but then receives a follower check from the leader. If the leader
 * does not notice the node disconnecting, it is important for the node not to be turned back into a follower but try
 * and join the leader again.
 */
public void testStayCandidateAfterReceivingFollowerCheckFromKnownMaster() {
    try (Cluster cluster = new Cluster(2, false, Settings.EMPTY)) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode leader = cluster.getAnyLeader();
        final ClusterNode nonLeader = cluster.getAnyNodeExcept(leader);
        nonLeader.onNode(() -> {
            logger.debug("forcing {} to become candidate", nonLeader.getId());
            synchronized (nonLeader.coordinator.mutex) {
                nonLeader.coordinator.becomeCandidate("forced");
            }
            logger.debug("simulate follower check coming through from {} to {}", leader.getId(), nonLeader.getId());
            expectThrows(CoordinationStateRejectedException.class, () -> nonLeader.coordinator.onFollowerCheckRequest(new FollowersChecker.FollowerCheckRequest(leader.coordinator.getCurrentTerm(), leader.getLocalNode())));
            assertThat(nonLeader.coordinator.getMode(), equalTo(CANDIDATE));
        }).run();
        cluster.stabilise();
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode)

Example 27 with ClusterNode

use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.

the class CoordinatorTests method testExpandsConfigurationWhenGrowingFromOneNodeToThreeButDoesNotShrink.

public void testExpandsConfigurationWhenGrowingFromOneNodeToThreeButDoesNotShrink() {
    try (Cluster cluster = new Cluster(1)) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode leader = cluster.getAnyLeader();
        cluster.addNodesAndStabilise(2);
        {
            assertThat(leader.coordinator.getMode(), is(Mode.LEADER));
            final VotingConfiguration lastCommittedConfiguration = leader.getLastAppliedClusterState().getLastCommittedConfiguration();
            assertThat(lastCommittedConfiguration + " should be all nodes", lastCommittedConfiguration.getNodeIds(), equalTo(cluster.clusterNodes.stream().map(ClusterNode::getId).collect(Collectors.toSet())));
        }
        final ClusterNode disconnect1 = cluster.getAnyNode();
        logger.info("--> disconnecting {}", disconnect1);
        disconnect1.disconnect();
        cluster.stabilise();
        {
            final ClusterNode newLeader = cluster.getAnyLeader();
            final VotingConfiguration lastCommittedConfiguration = newLeader.getLastAppliedClusterState().getLastCommittedConfiguration();
            assertThat(lastCommittedConfiguration + " should be all nodes", lastCommittedConfiguration.getNodeIds(), equalTo(cluster.clusterNodes.stream().map(ClusterNode::getId).collect(Collectors.toSet())));
        }
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 28 with ClusterNode

use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.

the class CoordinatorTests method testDiscoveryUsesNodesFromLastClusterState.

public void testDiscoveryUsesNodesFromLastClusterState() {
    try (Cluster cluster = new Cluster(randomIntBetween(3, 5))) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode partitionedNode = cluster.getAnyNode();
        if (randomBoolean()) {
            logger.info("--> blackholing {}", partitionedNode);
            partitionedNode.blackhole();
        } else {
            logger.info("--> disconnecting {}", partitionedNode);
            partitionedNode.disconnect();
        }
        cluster.setEmptySeedHostsList();
        cluster.stabilise();
        partitionedNode.heal();
        cluster.runRandomly(false);
        cluster.stabilise();
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode)

Example 29 with ClusterNode

use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.

the class CoordinatorTests method testDoesNotElectNonMasterNode.

public void testDoesNotElectNonMasterNode() {
    try (Cluster cluster = new Cluster(randomIntBetween(1, 5), false, Settings.EMPTY)) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode leader = cluster.getAnyLeader();
        assertTrue(leader.getLocalNode().isMasterEligibleNode());
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode)

Example 30 with ClusterNode

use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.

the class CoordinatorTests method testAckListenerReceivesNackFromFollower.

public void testAckListenerReceivesNackFromFollower() {
    try (Cluster cluster = new Cluster(3)) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode leader = cluster.getAnyLeader();
        final ClusterNode follower0 = cluster.getAnyNodeExcept(leader);
        final ClusterNode follower1 = cluster.getAnyNodeExcept(leader, follower0);
        follower0.allowClusterStateApplicationFailure();
        follower0.setClusterStateApplyResponse(ClusterStateApplyResponse.FAIL);
        AckCollector ackCollector = leader.submitValue(randomLong());
        cluster.stabilise(DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
        assertTrue("expected ack from " + leader, ackCollector.hasAckedSuccessfully(leader));
        assertTrue("expected nack from " + follower0, ackCollector.hasAckedUnsuccessfully(follower0));
        assertTrue("expected ack from " + follower1, ackCollector.hasAckedSuccessfully(follower1));
        assertThat("leader should be last to ack", ackCollector.getSuccessfulAckIndex(leader), equalTo(1));
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode)

Aggregations

ClusterNode (org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode)35 Matchers.containsString (org.hamcrest.Matchers.containsString)8 VotingConfiguration (org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)5 MockLogAppender (org.elasticsearch.test.MockLogAppender)5 HashSet (java.util.HashSet)4 ClusterState (org.elasticsearch.cluster.ClusterState)4 List (java.util.List)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Logger (org.apache.logging.log4j.Logger)3 LogEvent (org.apache.logging.log4j.core.LogEvent)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Level (org.apache.logging.log4j.Level)2 LogManager (org.apache.logging.log4j.LogManager)2