Search in sources :

Example 46 with RoutingAllocation

use of org.elasticsearch.cluster.routing.allocation.RoutingAllocation in project elasticsearch by elastic.

the class PrimaryShardAllocatorTests method testRestoreDoesNotAssignIfNoShardAvailable.

/**
     * Tests that when restoring from a snapshot and we don't find a node with a shard copy, the shard will remain in
     * the unassigned list to be allocated later.
     */
public void testRestoreDoesNotAssignIfNoShardAvailable() {
    RoutingAllocation allocation = getRestoreRoutingAllocation(yesAllocationDeciders(), "allocId");
    testAllocator.addData(node1, null, false);
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(false));
    assertThat(allocation.routingNodes().unassigned().ignored().isEmpty(), equalTo(true));
    assertThat(allocation.routingNodes().unassigned().size(), equalTo(1));
    assertClusterHealthStatus(allocation, ClusterHealthStatus.YELLOW);
}
Also used : RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 47 with RoutingAllocation

use of org.elasticsearch.cluster.routing.allocation.RoutingAllocation in project elasticsearch by elastic.

the class PrimaryShardAllocatorTests method testFoundAllocationAndAllocating.

/**
     * Tests that when there is a node to allocate the shard to, it will be allocated to it.
     */
public void testFoundAllocationAndAllocating() {
    final RoutingAllocation allocation = routingAllocationWithOnePrimaryNoReplicas(yesAllocationDeciders(), randomFrom(CLUSTER_RECOVERED, INDEX_REOPENED), "allocId1");
    testAllocator.addData(node1, "allocId1", randomBoolean());
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(true));
    assertThat(allocation.routingNodes().unassigned().ignored().isEmpty(), equalTo(true));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(node1.getId()));
    // check that allocation id is reused
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).allocationId().getId(), equalTo("allocId1"));
    assertClusterHealthStatus(allocation, ClusterHealthStatus.YELLOW);
}
Also used : RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 48 with RoutingAllocation

use of org.elasticsearch.cluster.routing.allocation.RoutingAllocation in project elasticsearch by elastic.

the class PrimaryShardAllocatorTests method testFoundAllocationButThrottlingDecider.

/**
     * Tests that when there is a node to allocate to, but it is throttling (and it is the only one),
     * it will be moved to ignore unassigned until it can be allocated to.
     */
public void testFoundAllocationButThrottlingDecider() {
    final RoutingAllocation allocation = routingAllocationWithOnePrimaryNoReplicas(throttleAllocationDeciders(), CLUSTER_RECOVERED, "allocId1");
    testAllocator.addData(node1, "allocId1", randomBoolean());
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(true));
    assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1));
    assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId));
    assertClusterHealthStatus(allocation, ClusterHealthStatus.YELLOW);
}
Also used : RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 49 with RoutingAllocation

use of org.elasticsearch.cluster.routing.allocation.RoutingAllocation in project elasticsearch by elastic.

the class PrimaryShardAllocatorTests method getRecoverOnAnyNodeRoutingAllocation.

private RoutingAllocation getRecoverOnAnyNodeRoutingAllocation(AllocationDeciders allocationDeciders, String... allocIds) {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder(shardId.getIndexName()).settings(settings(Version.CURRENT).put(IndexMetaData.SETTING_SHARED_FILESYSTEM, true).put(IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, true)).numberOfShards(1).numberOfReplicas(0).putInSyncAllocationIds(0, Sets.newHashSet(allocIds))).build();
    RoutingTable routingTable = RoutingTable.builder().addAsRestore(metaData.index(shardId.getIndex()), new SnapshotRecoverySource(new Snapshot("test", new SnapshotId("test", UUIDs.randomBase64UUID())), Version.CURRENT, shardId.getIndexName())).build();
    ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build();
    return new RoutingAllocation(allocationDeciders, new RoutingNodes(state, false), state, null, System.nanoTime(), false);
}
Also used : Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) ClusterState(org.elasticsearch.cluster.ClusterState) SnapshotRecoverySource(org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 50 with RoutingAllocation

use of org.elasticsearch.cluster.routing.allocation.RoutingAllocation in project elasticsearch by elastic.

the class PrimaryShardAllocatorTests method getRestoreRoutingAllocation.

private RoutingAllocation getRestoreRoutingAllocation(AllocationDeciders allocationDeciders, String... allocIds) {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder(shardId.getIndexName()).settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(0).putInSyncAllocationIds(0, Sets.newHashSet(allocIds))).build();
    final Snapshot snapshot = new Snapshot("test", new SnapshotId("test", UUIDs.randomBase64UUID()));
    RoutingTable routingTable = RoutingTable.builder().addAsRestore(metaData.index(shardId.getIndex()), new SnapshotRecoverySource(snapshot, Version.CURRENT, shardId.getIndexName())).build();
    ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build();
    return new RoutingAllocation(allocationDeciders, new RoutingNodes(state, false), state, null, System.nanoTime(), false);
}
Also used : Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) ClusterState(org.elasticsearch.cluster.ClusterState) SnapshotRecoverySource(org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Aggregations

RoutingAllocation (org.elasticsearch.cluster.routing.allocation.RoutingAllocation)54 ClusterState (org.elasticsearch.cluster.ClusterState)14 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)14 StoreFileMetaData (org.elasticsearch.index.store.StoreFileMetaData)14 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)12 MetaData (org.elasticsearch.cluster.metadata.MetaData)11 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)11 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)9 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)9 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)8 ClusterInfo (org.elasticsearch.cluster.ClusterInfo)7 UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)7 DevNullClusterInfo (org.elasticsearch.cluster.MockInternalClusterInfoService.DevNullClusterInfo)6 AllocationDeciders (org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders)6 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 TestShardRouting (org.elasticsearch.cluster.routing.TestShardRouting)5 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)5 DiskUsage (org.elasticsearch.cluster.DiskUsage)4 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)4