Search in sources :

Example 6 with ClusterChangedEvent

use of org.elasticsearch.cluster.ClusterChangedEvent in project elasticsearch by elastic.

the class GatewayMetaStateTests method testAllUpToDateNothingWritten.

public void testAllUpToDateNothingWritten() throws Exception {
    // make sure state is not written again if we wrote already
    boolean initializing = false;
    boolean versionChanged = false;
    boolean stateInMemory = true;
    boolean masterEligible = randomBoolean();
    boolean expectMetaData = false;
    ClusterChangedEvent event = generateEvent(initializing, versionChanged, masterEligible);
    assertState(event, stateInMemory, expectMetaData);
}
Also used : ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent)

Example 7 with ClusterChangedEvent

use of org.elasticsearch.cluster.ClusterChangedEvent in project elasticsearch by elastic.

the class GatewayMetaStateTests method testWriteClosedIndex.

public void testWriteClosedIndex() throws Exception {
    // test that the closing of an index is written also on data only node
    boolean masterEligible = randomBoolean();
    boolean expectMetaData = true;
    boolean stateInMemory = true;
    ClusterChangedEvent event = generateCloseEvent(masterEligible);
    assertState(event, stateInMemory, expectMetaData);
}
Also used : ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent)

Example 8 with ClusterChangedEvent

use of org.elasticsearch.cluster.ClusterChangedEvent in project elasticsearch by elastic.

the class GatewayMetaStateTests method testNoWriteIfNothingChanged.

public void testNoWriteIfNothingChanged() throws Exception {
    boolean initializing = false;
    boolean versionChanged = false;
    boolean stateInMemory = true;
    boolean masterEligible = randomBoolean();
    boolean expectMetaData = false;
    ClusterChangedEvent event = generateEvent(initializing, versionChanged, masterEligible);
    ClusterChangedEvent newEventWithNothingChanged = new ClusterChangedEvent("test cluster state", event.state(), event.state());
    assertState(newEventWithNothingChanged, stateInMemory, expectMetaData);
}
Also used : ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent)

Example 9 with ClusterChangedEvent

use of org.elasticsearch.cluster.ClusterChangedEvent in project elasticsearch by elastic.

the class DelayedAllocationServiceTests method testNoDelayedUnassigned.

public void testNoDelayedUnassigned() throws Exception {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT).put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "0")).numberOfShards(1).numberOfReplicas(1)).build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build();
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).localNodeId("node1").masterNodeId("node1")).build();
    clusterState = allocationService.reroute(clusterState, "reroute");
    // starting primaries
    clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    // starting replicas
    clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
    ClusterState prevState = clusterState;
    // remove node2 and reroute
    DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterState.nodes()).remove("node2");
    boolean nodeAvailableForAllocation = randomBoolean();
    if (nodeAvailableForAllocation) {
        nodes.add(newNode("node3"));
    }
    clusterState = ClusterState.builder(clusterState).nodes(nodes).build();
    clusterState = allocationService.deassociateDeadNodes(clusterState, true, "reroute");
    ClusterState newState = clusterState;
    List<ShardRouting> unassignedShards = newState.getRoutingTable().shardsWithState(ShardRoutingState.UNASSIGNED);
    if (nodeAvailableForAllocation) {
        assertThat(unassignedShards.size(), equalTo(0));
    } else {
        assertThat(unassignedShards.size(), equalTo(1));
        assertThat(unassignedShards.get(0).unassignedInfo().isDelayed(), equalTo(false));
    }
    delayedAllocationService.clusterChanged(new ClusterChangedEvent("test", newState, prevState));
    verifyNoMoreInteractions(clusterService);
    assertNull(delayedAllocationService.delayedRerouteTask.get());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 10 with ClusterChangedEvent

use of org.elasticsearch.cluster.ClusterChangedEvent in project elasticsearch by elastic.

the class IndicesClusterStateServiceRandomUpdatesTests method testRandomClusterStateUpdates.

public void testRandomClusterStateUpdates() {
    // we have an IndicesClusterStateService per node in the cluster
    final Map<DiscoveryNode, IndicesClusterStateService> clusterStateServiceMap = new HashMap<>();
    ClusterState state = randomInitialClusterState(clusterStateServiceMap, MockIndicesService::new);
    // each of the following iterations represents a new cluster state update processed on all nodes
    for (int i = 0; i < 30; i++) {
        logger.info("Iteration {}", i);
        final ClusterState previousState = state;
        // calculate new cluster state
        for (int j = 0; j < randomInt(3); j++) {
            // multiple iterations to simulate batching of cluster states
            try {
                state = randomlyUpdateClusterState(state, clusterStateServiceMap, MockIndicesService::new);
            } catch (AssertionError error) {
                ClusterState finalState = state;
                logger.error((org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage("failed to random change state. last good state: \n{}", finalState), error);
                throw error;
            }
        }
        // apply cluster state to nodes (incl. master)
        for (DiscoveryNode node : state.nodes()) {
            IndicesClusterStateService indicesClusterStateService = clusterStateServiceMap.get(node);
            ClusterState localState = adaptClusterStateToLocalNode(state, node);
            ClusterState previousLocalState = adaptClusterStateToLocalNode(previousState, node);
            final ClusterChangedEvent event = new ClusterChangedEvent("simulated change " + i, localState, previousLocalState);
            try {
                indicesClusterStateService.applyClusterState(event);
            } catch (AssertionError error) {
                logger.error((org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage("failed to apply change on [{}].\n ***  Previous state ***\n{}\n ***  New state ***\n{}", node, event.previousState(), event.state()), error);
                throw error;
            }
            // check that cluster state has been properly applied to node
            assertClusterStateMatchesNodeState(localState, indicesClusterStateService);
        }
    }
    // TODO: check if we can go to green by starting all shards and finishing all iterations
    logger.info("Final cluster state: {}", state);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) Supplier(java.util.function.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Aggregations

ClusterChangedEvent (org.elasticsearch.cluster.ClusterChangedEvent)27 ClusterState (org.elasticsearch.cluster.ClusterState)20 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)8 MetaData (org.elasticsearch.cluster.metadata.MetaData)8 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)7 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)7 Settings (org.elasticsearch.common.settings.Settings)7 Discovery (org.elasticsearch.discovery.Discovery)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ClusterStateListener (org.elasticsearch.cluster.ClusterStateListener)4 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)4 TimeValue (org.elasticsearch.common.unit.TimeValue)4 DiscoverySettings (org.elasticsearch.discovery.DiscoverySettings)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)3 ClusterStateUpdateTask (org.elasticsearch.cluster.ClusterStateUpdateTask)3 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)3 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)3 ShardId (org.elasticsearch.index.shard.ShardId)3