Search in sources :

Example 21 with RoutingAllocation

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

the class PrimaryShardAllocatorTests method routingAllocationWithOnePrimaryNoReplicas.

private RoutingAllocation routingAllocationWithOnePrimaryNoReplicas(AllocationDeciders deciders, UnassignedInfo.Reason reason, String... activeAllocationIds) {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder(shardId.getIndexName()).settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(0).putInSyncAllocationIds(shardId.id(), Sets.newHashSet(activeAllocationIds))).build();
    RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
    switch(reason) {
        case INDEX_CREATED:
            routingTableBuilder.addAsNew(metaData.index(shardId.getIndex()));
            break;
        case CLUSTER_RECOVERED:
            routingTableBuilder.addAsRecovery(metaData.index(shardId.getIndex()));
            break;
        case INDEX_REOPENED:
            routingTableBuilder.addAsFromCloseToOpen(metaData.index(shardId.getIndex()));
            break;
        default:
            throw new IllegalArgumentException("can't do " + reason + " for you. teach me");
    }
    ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTableBuilder.build()).nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build();
    return new RoutingAllocation(deciders, new RoutingNodes(state, false), state, null, System.nanoTime(), false);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) 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 22 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method testDelayedAllocation.

public void testDelayedAllocation() {
    RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders(), Settings.builder().put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueHours(1)).build(), UnassignedInfo.Reason.NODE_LEFT);
    testAllocator.addData(node1, "MATCH", new StoreFileMetaData("file1", 10, "MATCH_CHECKSUM"));
    if (randomBoolean()) {
        // we sometime return empty list of files, make sure we test this as well
        testAllocator.addData(node2, null);
    }
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(false));
    assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1));
    assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId));
    allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders(), Settings.builder().put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueHours(1)).build(), UnassignedInfo.Reason.NODE_LEFT);
    testAllocator.addData(node2, "MATCH", new StoreFileMetaData("file1", 10, "MATCH_CHECKSUM"));
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(true));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(node2.getId()));
}
Also used : StoreFileMetaData(org.elasticsearch.index.store.StoreFileMetaData) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 23 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method testNoAsyncFetchData.

/**
     * Verifies that when we are still fetching data in an async manner, the replica shard moves to ignore unassigned.
     */
public void testNoAsyncFetchData() {
    RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders());
    testAllocator.clean();
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1));
    assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId));
}
Also used : RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 24 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method testFileChecksumMatch.

/**
     * Verifies that when there is no sync id match but files match, we allocate it to matching node.
     */
public void testFileChecksumMatch() {
    RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders());
    DiscoveryNode nodeToMatch = randomBoolean() ? node2 : node3;
    testAllocator.addData(node1, "MATCH", new StoreFileMetaData("file1", 10, "MATCH_CHECKSUM")).addData(nodeToMatch, "NO_MATCH", new StoreFileMetaData("file1", 10, "MATCH_CHECKSUM"));
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(nodeToMatch.getId()));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) StoreFileMetaData(org.elasticsearch.index.store.StoreFileMetaData) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 25 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method testAsyncFetchOnAnythingButIndexCreation.

/**
     * Verifies that for anything but index creation, fetch data ends up being called, since we need to go and try
     * and find a better copy for the shard.
     */
public void testAsyncFetchOnAnythingButIndexCreation() {
    UnassignedInfo.Reason reason = RandomPicks.randomFrom(random(), EnumSet.complementOf(EnumSet.of(UnassignedInfo.Reason.INDEX_CREATED)));
    RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders(), Settings.EMPTY, reason);
    testAllocator.clean();
    testAllocator.allocateUnassigned(allocation);
    assertThat("failed with reason " + reason, testAllocator.getFetchDataCalledAndClean(), equalTo(true));
}
Also used : UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Aggregations

RoutingAllocation (org.elasticsearch.cluster.routing.allocation.RoutingAllocation)88 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)27 ClusterState (org.elasticsearch.cluster.ClusterState)24 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)20 StoreFileMetadata (org.elasticsearch.index.store.StoreFileMetadata)20 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)19 UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)18 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)16 ClusterInfo (org.elasticsearch.cluster.ClusterInfo)15 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)15 StoreFileMetaData (org.elasticsearch.index.store.StoreFileMetaData)14 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)12 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)11 MetaData (org.elasticsearch.cluster.metadata.MetaData)11 TestShardRouting (org.elasticsearch.cluster.routing.TestShardRouting)11 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)11 ShardId (org.elasticsearch.index.shard.ShardId)11 DiskUsage (org.elasticsearch.cluster.DiskUsage)9