Search in sources :

Example 81 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method testNoPrimaryData.

/**
 * When we can't find primary data, but still find replica data, we go ahead and keep it unassigned
 * to be allocated. This is today behavior, which relies on a primary corruption identified with
 * adding a replica and having that replica actually recover and cause the corruption to be identified
 * See CorruptFileTest#
 */
public void testNoPrimaryData() {
    RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders());
    testAllocator.addData(node2, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(1));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).get(0).shardId(), equalTo(shardId));
}
Also used : StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 82 with RoutingAllocation

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

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", MIN_SUPPORTED_LUCENE_VERSION));
    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", MIN_SUPPORTED_LUCENE_VERSION));
    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 83 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method testNotCancellingRecoveryIfSyncedOnExistingRecovery.

public void testNotCancellingRecoveryIfSyncedOnExistingRecovery() {
    final UnassignedInfo unassignedInfo;
    if (randomBoolean()) {
        unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.CLUSTER_RECOVERED, null);
    } else {
        unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.ALLOCATION_FAILED, null, null, randomIntBetween(1, 10), System.nanoTime(), System.currentTimeMillis(), false, UnassignedInfo.AllocationStatus.NO_ATTEMPT, Set.of("node-4"));
    }
    RoutingAllocation allocation = onePrimaryOnNode1And1ReplicaRecovering(yesAllocationDeciders(), unassignedInfo);
    List<RetentionLease> retentionLeases = new ArrayList<>();
    if (randomBoolean()) {
        long retainingSeqNoOnPrimary = randomLongBetween(0, Long.MAX_VALUE);
        retentionLeases.add(newRetentionLease(node1, retainingSeqNoOnPrimary));
        if (randomBoolean()) {
            retentionLeases.add(newRetentionLease(node2, randomLongBetween(0, retainingSeqNoOnPrimary)));
        }
        if (randomBoolean()) {
            retentionLeases.add(newRetentionLease(node3, randomLongBetween(0, retainingSeqNoOnPrimary)));
        }
    }
    testAllocator.addData(node1, retentionLeases, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.addData(node2, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.addData(node3, randomSyncId(), new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.processExistingRecoveries(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(false));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(0));
}
Also used : UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) RetentionLease(org.elasticsearch.index.seqno.RetentionLease) ArrayList(java.util.ArrayList) StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 84 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method testThrottleWhenAllocatingToMatchingNode.

/**
 * Tests when the node to allocate to due to matching is being throttled, we move the shard to ignored
 * to wait till throttling on it is done.
 */
public void testThrottleWhenAllocatingToMatchingNode() {
    RoutingAllocation allocation = onePrimaryOnNode1And1Replica(new AllocationDeciders(Arrays.asList(new TestAllocateDecision(Decision.YES), new SameShardAllocationDecider(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), new AllocationDecider() {

        @Override
        public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
            if (node.node().equals(node2)) {
                return Decision.THROTTLE;
            }
            return Decision.YES;
        }
    })));
    testAllocator.addData(node1, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION)).addData(node2, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION));
    testAllocator.allocateUnassigned(allocation);
    assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1));
    assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId));
}
Also used : SameShardAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) SameShardAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider) AllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision)

Example 85 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method onePrimaryOnNode1And1ReplicaRecovering.

private RoutingAllocation onePrimaryOnNode1And1ReplicaRecovering(AllocationDeciders deciders, UnassignedInfo unassignedInfo) {
    ShardRouting primaryShard = TestShardRouting.newShardRouting(shardId, node1.getId(), true, ShardRoutingState.STARTED);
    Metadata metaData = Metadata.builder().put(IndexMetadata.builder(shardId.getIndexName()).settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1).putInSyncAllocationIds(0, Set.of(primaryShard.allocationId().getId()))).build();
    RoutingTable routingTable = RoutingTable.builder().add(IndexRoutingTable.builder(shardId.getIndex()).addIndexShard(new IndexShardRoutingTable.Builder(shardId).addShard(primaryShard).addShard(TestShardRouting.newShardRouting(shardId, node2.getId(), null, false, ShardRoutingState.INITIALIZING, unassignedInfo)).build())).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(deciders, new RoutingNodes(state, false), state, ClusterInfo.EMPTY, System.nanoTime());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) StoreFileMetadata(org.elasticsearch.index.store.StoreFileMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) TransportNodesListShardStoreMetadata(org.elasticsearch.indices.store.TransportNodesListShardStoreMetadata) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) 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