Search in sources :

Example 56 with ClusterState

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

the class RoutingTableTests method initPrimaries.

/**
     * puts primary shard routings into initializing state
     */
private void initPrimaries() {
    logger.info("adding {} nodes and performing rerouting", this.numberOfReplicas + 1);
    Builder discoBuilder = DiscoveryNodes.builder();
    for (int i = 0; i < this.numberOfReplicas + 1; i++) {
        discoBuilder = discoBuilder.add(newNode("node" + i));
    }
    this.clusterState = ClusterState.builder(clusterState).nodes(discoBuilder).build();
    ClusterState rerouteResult = ALLOCATION_SERVICE.reroute(clusterState, "reroute");
    assertThat(rerouteResult, not(equalTo(this.clusterState)));
    this.clusterState = rerouteResult;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Builder(org.elasticsearch.cluster.node.DiscoveryNodes.Builder)

Example 57 with ClusterState

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

the class UnassignedInfoTests method testFindNextDelayedAllocation.

public void testFindNextDelayedAllocation() {
    MockAllocationService allocation = createAllocationService(Settings.EMPTY, new DelayedShardsMockGatewayAllocator());
    final TimeValue delayTest1 = TimeValue.timeValueMillis(randomIntBetween(1, 200));
    final TimeValue delayTest2 = TimeValue.timeValueMillis(randomIntBetween(1, 200));
    final long expectMinDelaySettingsNanos = Math.min(delayTest1.nanos(), delayTest2.nanos());
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT).put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), delayTest1)).numberOfShards(1).numberOfReplicas(1)).put(IndexMetaData.builder("test2").settings(settings(Version.CURRENT).put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), delayTest2)).numberOfShards(1).numberOfReplicas(1)).build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(RoutingTable.builder().addAsNew(metaData.index("test1")).addAsNew(metaData.index("test2")).build()).build();
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
    clusterState = allocation.reroute(clusterState, "reroute");
    assertThat(UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), equalTo(0));
    // starting primaries
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    // starting replicas
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
    // remove node2 and reroute
    final long baseTime = System.nanoTime();
    allocation.setNanoTimeOverride(baseTime);
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node2")).build();
    clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
    final long delta = randomBoolean() ? 0 : randomInt((int) expectMinDelaySettingsNanos - 1);
    if (delta > 0) {
        allocation.setNanoTimeOverride(baseTime + delta);
        clusterState = allocation.reroute(clusterState, "time moved");
    }
    assertThat(UnassignedInfo.findNextDelayedAllocation(baseTime + delta, clusterState), equalTo(expectMinDelaySettingsNanos - delta));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 58 with ClusterState

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

the class UnassignedInfoTests method testIndexCreated.

public void testIndexCreated() {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(randomIntBetween(1, 3)).numberOfReplicas(randomIntBetween(0, 3))).build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build();
    for (ShardRouting shard : clusterState.getRoutingNodes().shardsWithState(UNASSIGNED)) {
        assertThat(shard.unassignedInfo().getReason(), equalTo(UnassignedInfo.Reason.INDEX_CREATED));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 59 with ClusterState

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

the class UnassignedInfoTests method testClusterRecovered.

public void testClusterRecovered() {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(randomIntBetween(1, 3)).numberOfReplicas(randomIntBetween(0, 3))).build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(RoutingTable.builder().addAsRecovery(metaData.index("test")).build()).build();
    for (ShardRouting shard : clusterState.getRoutingNodes().shardsWithState(UNASSIGNED)) {
        assertThat(shard.unassignedInfo().getReason(), equalTo(UnassignedInfo.Reason.CLUSTER_RECOVERED));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 60 with ClusterState

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

the class UnassignedInfoTests method testNumberOfDelayedUnassigned.

public void testNumberOfDelayedUnassigned() throws Exception {
    MockAllocationService allocation = createAllocationService(Settings.EMPTY, new DelayedShardsMockGatewayAllocator());
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)).put(IndexMetaData.builder("test2").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)).build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(RoutingTable.builder().addAsNew(metaData.index("test1")).addAsNew(metaData.index("test2")).build()).build();
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
    clusterState = allocation.reroute(clusterState, "reroute");
    assertThat(UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), equalTo(0));
    // starting primaries
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    // starting replicas
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
    // remove node2 and reroute
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node2")).build();
    // make sure both replicas are marked as delayed (i.e. not reallocated)
    clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
    assertThat(clusterState.toString(), UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), equalTo(2));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

ClusterState (org.elasticsearch.cluster.ClusterState)564 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)211 MetaData (org.elasticsearch.cluster.metadata.MetaData)179 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)150 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)123 Settings (org.elasticsearch.common.settings.Settings)100 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)85 ClusterName (org.elasticsearch.cluster.ClusterName)82 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)75 Matchers.containsString (org.hamcrest.Matchers.containsString)72 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)62 ShardId (org.elasticsearch.index.shard.ShardId)61 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)59 ArrayList (java.util.ArrayList)57 IOException (java.io.IOException)55 Index (org.elasticsearch.index.Index)53 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)49 CountDownLatch (java.util.concurrent.CountDownLatch)47 HashSet (java.util.HashSet)45 List (java.util.List)45