Search in sources :

Example 31 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method onePrimaryOnNode1And1ReplicaRecovering.

private RoutingAllocation onePrimaryOnNode1And1ReplicaRecovering(AllocationDeciders deciders) {
    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, Sets.newHashSet(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, new UnassignedInfo(UnassignedInfo.Reason.CLUSTER_RECOVERED, null))).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(), false);
}
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) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) MetaData(org.elasticsearch.cluster.metadata.MetaData) StoreFileMetaData(org.elasticsearch.index.store.StoreFileMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) TransportNodesListShardStoreMetaData(org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 32 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method testNotCancellingRecoveryIfSyncedOnExistingRecovery.

public void testNotCancellingRecoveryIfSyncedOnExistingRecovery() {
    RoutingAllocation allocation = onePrimaryOnNode1And1ReplicaRecovering(yesAllocationDeciders());
    testAllocator.addData(node1, "MATCH", new StoreFileMetaData("file1", 10, "MATCH_CHECKSUM")).addData(node2, "MATCH", new StoreFileMetaData("file1", 10, "MATCH_CHECKSUM")).addData(node3, randomBoolean() ? "MATCH" : "NO_MATCH", new StoreFileMetaData("file1", 10, "MATCH_CHECKSUM"));
    testAllocator.processExistingRecoveries(allocation);
    assertThat(allocation.routingNodesChanged(), equalTo(false));
    assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(0));
}
Also used : StoreFileMetaData(org.elasticsearch.index.store.StoreFileMetaData) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 33 with RoutingAllocation

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

the class ReplicaShardAllocatorTests method onePrimaryOnNode1And1Replica.

private RoutingAllocation onePrimaryOnNode1And1Replica(AllocationDeciders deciders, Settings settings, UnassignedInfo.Reason reason) {
    ShardRouting primaryShard = TestShardRouting.newShardRouting(shardId, node1.getId(), true, ShardRoutingState.STARTED);
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder(shardId.getIndexName()).settings(settings(Version.CURRENT).put(settings)).numberOfShards(1).numberOfReplicas(1).putInSyncAllocationIds(0, Sets.newHashSet(primaryShard.allocationId().getId()))).build();
    // mark shard as delayed if reason is NODE_LEFT
    boolean delayed = reason == UnassignedInfo.Reason.NODE_LEFT && UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.get(settings).nanos() > 0;
    int failedAllocations = reason == UnassignedInfo.Reason.ALLOCATION_FAILED ? 1 : 0;
    RoutingTable routingTable = RoutingTable.builder().add(IndexRoutingTable.builder(shardId.getIndex()).addIndexShard(new IndexShardRoutingTable.Builder(shardId).addShard(primaryShard).addShard(ShardRouting.newUnassigned(shardId, false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(reason, null, null, failedAllocations, System.nanoTime(), System.currentTimeMillis(), delayed, UnassignedInfo.AllocationStatus.NO_ATTEMPT))).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(), false);
}
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) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) MetaData(org.elasticsearch.cluster.metadata.MetaData) StoreFileMetaData(org.elasticsearch.index.store.StoreFileMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) TransportNodesListShardStoreMetaData(org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation)

Example 34 with RoutingAllocation

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

the class DecommissionAllocationDeciderTest method setUp.

@Before
public void setUp() throws Exception {
    routingAllocation = mock(RoutingAllocation.class);
    when(routingAllocation.decision(any(Decision.class), anyString(), anyString())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArguments()[0];
        }
    });
    primaryShard = ShardRouting.newUnassigned("t", 0, mock(RestoreSource.class), true, mock(UnassignedInfo.class));
    replicaShard = ShardRouting.newUnassigned("t", 0, mock(RestoreSource.class), false, mock(UnassignedInfo.class));
    n1 = new RoutingNode("n1", mock(DiscoveryNode.class));
    n2 = new RoutingNode("n2", mock(DiscoveryNode.class));
}
Also used : RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) Before(org.junit.Before)

Example 35 with RoutingAllocation

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

the class DecommissionAllocationDeciderTest method init.

@Before
public void init() throws Exception {
    routingAllocation = mock(RoutingAllocation.class);
    when(routingAllocation.decision(any(Decision.class), anyString(), anyString())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArguments()[0];
        }
    });
    primaryShard = ShardRouting.newUnassigned(new ShardId("t", UUIDs.randomBase64UUID(), 0), true, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "dummy"));
    replicaShard = ShardRouting.newUnassigned(new ShardId("t", UUIDs.randomBase64UUID(), 0), false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "dummy"));
    n1 = new RoutingNode("n1", mock(DiscoveryNode.class));
    n2 = new RoutingNode("n2", mock(DiscoveryNode.class));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) Before(org.junit.Before)

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