Search in sources :

Example 31 with VotingConfiguration

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

the class NodeJoinTests method testJoinAccumulation.

public void testJoinAccumulation() {
    DiscoveryNode node0 = newNode(0, true);
    DiscoveryNode node1 = newNode(1, true);
    DiscoveryNode node2 = newNode(2, true);
    long initialTerm = randomLongBetween(1, 10);
    long initialVersion = randomLongBetween(1, 10);
    setupFakeMasterServiceAndCoordinator(initialTerm, initialState(node0, initialTerm, initialVersion, new VotingConfiguration(Collections.singleton(node2.getId()))));
    assertFalse(isLocalNodeElectedMaster());
    long newTerm = initialTerm + randomLongBetween(1, 10);
    SimpleFuture futNode0 = joinNodeAsync(new JoinRequest(node0, Optional.of(new Join(node0, node0, newTerm, initialTerm, initialVersion))));
    deterministicTaskQueue.runAllRunnableTasks();
    assertFalse(futNode0.isDone());
    assertFalse(isLocalNodeElectedMaster());
    SimpleFuture futNode1 = joinNodeAsync(new JoinRequest(node1, Optional.of(new Join(node1, node0, newTerm, initialTerm, initialVersion))));
    deterministicTaskQueue.runAllRunnableTasks();
    assertFalse(futNode1.isDone());
    assertFalse(isLocalNodeElectedMaster());
    joinNodeAndRun(new JoinRequest(node2, Optional.of(new Join(node2, node0, newTerm, initialTerm, initialVersion))));
    assertTrue(isLocalNodeElectedMaster());
    assertTrue(clusterStateHasNode(node1));
    assertTrue(clusterStateHasNode(node2));
    FutureUtils.get(futNode0);
    FutureUtils.get(futNode1);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 32 with VotingConfiguration

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

the class NodeJoinTests method testBecomeFollowerFailsPendingJoin.

public void testBecomeFollowerFailsPendingJoin() throws Exception {
    DiscoveryNode node0 = newNode(0, true);
    DiscoveryNode node1 = newNode(1, true);
    long initialTerm = randomLongBetween(1, 10);
    long initialVersion = randomLongBetween(1, 10);
    setupFakeMasterServiceAndCoordinator(initialTerm, initialState(node0, initialTerm, initialVersion, new VotingConfiguration(Collections.singleton(node1.getId()))));
    long newTerm = initialTerm + randomLongBetween(1, 10);
    SimpleFuture fut = joinNodeAsync(new JoinRequest(node0, Optional.of(new Join(node0, node0, newTerm, initialTerm, initialVersion))));
    deterministicTaskQueue.runAllRunnableTasks();
    assertFalse(fut.isDone());
    assertFalse(isLocalNodeElectedMaster());
    handleFollowerCheckFrom(node1, newTerm);
    assertFalse(isLocalNodeElectedMaster());
    assertThat(expectThrows(CoordinationStateRejectedException.class, () -> FutureUtils.get(fut)).getMessage(), containsString("became follower"));
    assertFalse(isLocalNodeElectedMaster());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 33 with VotingConfiguration

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

the class CoordinationState method setInitialState.

/**
 * Used to bootstrap a cluster by injecting the initial state and configuration.
 *
 * @param initialState The initial state to use. Must have term 0, version equal to the last-accepted version, and non-empty
 *                     configurations.
 * @throws CoordinationStateRejectedException if the arguments were incompatible with the current state of this object.
 */
public void setInitialState(ClusterState initialState) {
    final VotingConfiguration lastAcceptedConfiguration = getLastAcceptedConfiguration();
    if (lastAcceptedConfiguration.isEmpty() == false) {
        LOGGER.debug("setInitialState: rejecting since last-accepted configuration is nonempty: {}", lastAcceptedConfiguration);
        throw new CoordinationStateRejectedException("initial state already set: last-accepted configuration now " + lastAcceptedConfiguration);
    }
    assert getLastAcceptedTerm() == 0 : getLastAcceptedTerm();
    assert getLastCommittedConfiguration().isEmpty() : getLastCommittedConfiguration();
    assert lastPublishedVersion == 0 : lastPublishedVersion;
    assert lastPublishedConfiguration.isEmpty() : lastPublishedConfiguration;
    assert electionWon == false;
    assert joinVotes.isEmpty() : joinVotes;
    assert publishVotes.isEmpty() : publishVotes;
    assert initialState.term() == 0 : initialState + " should have term 0";
    assert initialState.version() == getLastAcceptedVersion() : initialState + " should have version " + getLastAcceptedVersion();
    assert initialState.getLastAcceptedConfiguration().isEmpty() == false;
    assert initialState.getLastCommittedConfiguration().isEmpty() == false;
    persistedState.setLastAcceptedState(initialState);
}
Also used : VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 34 with VotingConfiguration

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

the class Coordinator method improveConfiguration.

// Package-private for testing
ClusterState improveConfiguration(ClusterState clusterState) {
    assert Thread.holdsLock(mutex) : "Coordinator mutex not held";
    // exclude any nodes whose ID is in the voting config exclusions list ...
    final Stream<String> excludedNodeIds = clusterState.getVotingConfigExclusions().stream().map(VotingConfigExclusion::getNodeId);
    // ... and also automatically exclude the node IDs of master-ineligible nodes that were previously master-eligible and are still in
    // the voting config. We could exclude all the master-ineligible nodes here, but there could be quite a few of them and that makes
    // the logging much harder to follow.
    final Stream<String> masterIneligibleNodeIdsInVotingConfig = StreamSupport.stream(clusterState.nodes().spliterator(), false).filter(n -> n.isMasterEligibleNode() == false && (clusterState.getLastAcceptedConfiguration().getNodeIds().contains(n.getId()) || clusterState.getLastCommittedConfiguration().getNodeIds().contains(n.getId()))).map(DiscoveryNode::getId);
    final Set<DiscoveryNode> liveNodes = StreamSupport.stream(clusterState.nodes().spliterator(), false).filter(DiscoveryNode::isMasterEligibleNode).filter(coordinationState.get()::containsJoinVoteFor).collect(Collectors.toSet());
    final VotingConfiguration newConfig = reconfigurator.reconfigure(liveNodes, Stream.concat(masterIneligibleNodeIdsInVotingConfig, excludedNodeIds).collect(Collectors.toSet()), getLocalNode(), clusterState.getLastAcceptedConfiguration());
    if (newConfig.equals(clusterState.getLastAcceptedConfiguration()) == false) {
        assert coordinationState.get().joinVotesHaveQuorumFor(newConfig);
        return ClusterState.builder(clusterState).metadata(Metadata.builder(clusterState.metadata()).coordinationMetadata(CoordinationMetadata.builder(clusterState.coordinationMetadata()).lastAcceptedConfiguration(newConfig).build())).build();
    }
    return clusterState;
}
Also used : VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) NO_MASTER_BLOCK_ID(org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_ID) RerouteService(org.elasticsearch.cluster.routing.RerouteService) Level(org.apache.logging.log4j.Level) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) Random(java.util.Random) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) JsonXContent(org.elasticsearch.common.xcontent.json.JsonXContent) STATE_NOT_RECOVERED_BLOCK(org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK) PeerFinder(org.elasticsearch.discovery.PeerFinder) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Settings(org.elasticsearch.common.settings.Settings) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) FollowerCheckRequest(org.elasticsearch.cluster.coordination.FollowersChecker.FollowerCheckRequest) ClusterName(org.elasticsearch.cluster.ClusterName) Releasable(org.elasticsearch.common.lease.Releasable) DiscoveryStats(org.elasticsearch.discovery.DiscoveryStats) Priority(org.elasticsearch.common.Priority) InitialJoinAccumulator(org.elasticsearch.cluster.coordination.JoinHelper.InitialJoinAccumulator) Setting(org.elasticsearch.common.settings.Setting) ClusterApplier(org.elasticsearch.cluster.service.ClusterApplier) Collection(java.util.Collection) Set(java.util.Set) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ClusterStateUpdaters.hideStateIfNotRecovered(org.elasticsearch.gateway.ClusterStateUpdaters.hideStateIfNotRecovered) TimeValue(io.crate.common.unit.TimeValue) Optional(java.util.Optional) Empty(org.elasticsearch.transport.TransportResponse.Empty) SeedHostsProvider(org.elasticsearch.discovery.SeedHostsProvider) ListenableFuture(org.elasticsearch.common.util.concurrent.ListenableFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Names(org.elasticsearch.threadpool.ThreadPool.Names) Supplier(java.util.function.Supplier) Strings(org.elasticsearch.common.Strings) ArrayList(java.util.ArrayList) XContentHelper(org.elasticsearch.common.xcontent.XContentHelper) HashSet(java.util.HashSet) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) HandshakingTransportAddressConnector(org.elasticsearch.discovery.HandshakingTransportAddressConnector) DiscoveryModule(org.elasticsearch.discovery.DiscoveryModule) BiConsumer(java.util.function.BiConsumer) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) StreamSupport(java.util.stream.StreamSupport) TransportService(org.elasticsearch.transport.TransportService) Nullable(javax.annotation.Nullable) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) SetOnce(org.apache.lucene.util.SetOnce) MasterService(org.elasticsearch.cluster.service.MasterService) Discovery(org.elasticsearch.discovery.Discovery) ClusterStateTaskConfig(org.elasticsearch.cluster.ClusterStateTaskConfig) IOException(java.io.IOException) AbstractLifecycleComponent(org.elasticsearch.common.component.AbstractLifecycleComponent) Scheduler(org.elasticsearch.threadpool.Scheduler) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) SeedHostsResolver(org.elasticsearch.discovery.SeedHostsResolver) LocalClusterUpdateTask(org.elasticsearch.cluster.LocalClusterUpdateTask) ClusterApplyListener(org.elasticsearch.cluster.service.ClusterApplier.ClusterApplyListener) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) ActionListener(org.elasticsearch.action.ActionListener) ClusterFormationState(org.elasticsearch.cluster.coordination.ClusterFormationFailureHelper.ClusterFormationState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Example 35 with VotingConfiguration

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

the class TransportAddVotingConfigExclusionsActionTests method setupForTest.

@Before
public void setupForTest() {
    final MockTransport transport = new MockTransport();
    transportService = transport.createTransportService(Settings.EMPTY, threadPool, boundTransportAddress -> localNode, null);
    new TransportAddVotingConfigExclusionsAction(transportService, clusterService, threadPool, // registers action
    new IndexNameExpressionResolver());
    transportService.start();
    transportService.acceptIncomingRequests();
    final VotingConfiguration allNodesConfig = VotingConfiguration.of(localNode, otherNode1, otherNode2);
    setState(clusterService, builder(new ClusterName("cluster")).nodes(new Builder().add(localNode).add(otherNode1).add(otherNode2).add(otherDataNode).localNodeId(localNode.getId()).masterNodeId(localNode.getId())).metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().lastAcceptedConfiguration(allNodesConfig).lastCommittedConfiguration(allNodesConfig).build())));
    clusterStateObserver = new ClusterStateObserver(clusterService, null, logger);
}
Also used : Builder(org.elasticsearch.cluster.node.DiscoveryNodes.Builder) Listener(org.elasticsearch.cluster.ClusterStateObserver.Listener) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Settings(org.elasticsearch.common.settings.Settings) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ClusterName(org.elasticsearch.cluster.ClusterName) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) AfterClass(org.junit.AfterClass) Set(java.util.Set) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) Version(org.elasticsearch.Version) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TimeValue(io.crate.common.unit.TimeValue) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) TransportException(org.elasticsearch.transport.TransportException) BeforeClass(org.junit.BeforeClass) ClusterService(org.elasticsearch.cluster.service.ClusterService) ClusterState.builder(org.elasticsearch.cluster.ClusterState.builder) Names(org.elasticsearch.threadpool.ThreadPool.Names) HashSet(java.util.HashSet) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING(org.elasticsearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction.MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) SetOnce(org.apache.lucene.util.SetOnce) Collections.emptySet(java.util.Collections.emptySet) MockTransport(org.elasticsearch.test.transport.MockTransport) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) StreamInput(org.elasticsearch.common.io.stream.StreamInput) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) MockTransport(org.elasticsearch.test.transport.MockTransport) Builder(org.elasticsearch.cluster.node.DiscoveryNodes.Builder) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Before(org.junit.Before)

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