Search in sources :

Example 11 with Decision

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

the class DecommissionAllocationDeciderTest method testCannotAllocatePrimaryOrReplicaIfDataAvailabilityIsFull.

@Test
public void testCannotAllocatePrimaryOrReplicaIfDataAvailabilityIsFull() throws Exception {
    Settings settings = Settings.builder().put(DecommissioningService.GRACEFUL_STOP_MIN_AVAILABILITY_SETTING.getKey(), "full").put(DecommissioningService.DECOMMISSION_PREFIX + "n1", true).build();
    DecommissionAllocationDecider allocationDecider = new DecommissionAllocationDecider(settings, clusterService.getClusterSettings());
    Decision decision = allocationDecider.canAllocate(replicaShard, n1, routingAllocation);
    assertThat(decision.type(), is(Decision.Type.NO));
    decision = allocationDecider.canRemain(replicaShard, n1, routingAllocation);
    assertThat(decision.type(), is(Decision.Type.NO));
    decision = allocationDecider.canAllocate(primaryShard, n1, routingAllocation);
    assertThat(decision.type(), is(Decision.Type.NO));
    decision = allocationDecider.canRemain(primaryShard, n1, routingAllocation);
    assertThat(decision.type(), is(Decision.Type.NO));
}
Also used : Settings(org.elasticsearch.common.settings.Settings) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 12 with Decision

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

the class DecommissionAllocationDeciderTest method testDecommissionSettingsAreUpdated.

@Test
public void testDecommissionSettingsAreUpdated() {
    DecommissionAllocationDecider allocationDecider = new DecommissionAllocationDecider(Settings.EMPTY, clusterService.getClusterSettings());
    Settings settings = Settings.builder().put(DecommissioningService.GRACEFUL_STOP_MIN_AVAILABILITY_SETTING.getKey(), "full").put(DecommissioningService.DECOMMISSION_PREFIX + "n1", true).build();
    clusterService.getClusterSettings().applySettings(settings);
    Decision decision = allocationDecider.canAllocate(primaryShard, n1, routingAllocation);
    assertThat(decision.type(), is(Decision.Type.NO));
}
Also used : Settings(org.elasticsearch.common.settings.Settings) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 13 with Decision

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

the class DecommissionAllocationDeciderTest method testCanAlwaysAllocateIfDataAvailabilityIsNone.

@Test
public void testCanAlwaysAllocateIfDataAvailabilityIsNone() throws Exception {
    Settings settings = Settings.builder().put(DecommissioningService.GRACEFUL_STOP_MIN_AVAILABILITY_SETTING.getKey(), "none").put(DecommissioningService.DECOMMISSION_PREFIX + "n1", true).build();
    DecommissionAllocationDecider allocationDecider = new DecommissionAllocationDecider(settings, clusterService.getClusterSettings());
    Decision decision = allocationDecider.canAllocate(primaryShard, n1, routingAllocation);
    assertThat(decision.type(), is(Decision.Type.YES));
    decision = allocationDecider.canAllocate(primaryShard, n2, routingAllocation);
    assertThat(decision.type(), is(Decision.Type.YES));
}
Also used : Settings(org.elasticsearch.common.settings.Settings) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 14 with Decision

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

the class RerouteExplanation method readFrom.

public static RerouteExplanation readFrom(StreamInput in) throws IOException {
    AllocationCommand command = in.readNamedWriteable(AllocationCommand.class);
    Decision decisions = Decision.readFrom(in);
    return new RerouteExplanation(command, decisions);
}
Also used : AllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocationCommand) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision)

Example 15 with Decision

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

the class AllocateReplicaAllocationCommand method execute.

@Override
public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) {
    final DiscoveryNode discoNode;
    try {
        discoNode = allocation.nodes().resolveNode(node);
    } catch (IllegalArgumentException e) {
        return explainOrThrowRejectedCommand(explain, allocation, e);
    }
    final RoutingNodes routingNodes = allocation.routingNodes();
    RoutingNode routingNode = routingNodes.node(discoNode.getId());
    if (routingNode == null) {
        return explainOrThrowMissingRoutingNode(allocation, explain, discoNode);
    }
    try {
        allocation.routingTable().shardRoutingTable(index, shardId).primaryShard();
    } catch (IndexNotFoundException | ShardNotFoundException e) {
        return explainOrThrowRejectedCommand(explain, allocation, e);
    }
    ShardRouting primaryShardRouting = null;
    for (RoutingNode node : allocation.routingNodes()) {
        for (ShardRouting shard : node) {
            if (shard.getIndexName().equals(index) && shard.getId() == shardId && shard.primary()) {
                primaryShardRouting = shard;
                break;
            }
        }
    }
    if (primaryShardRouting == null) {
        return explainOrThrowRejectedCommand(explain, allocation, "trying to allocate a replica shard [" + index + "][" + shardId + "], while corresponding primary shard is still unassigned");
    }
    List<ShardRouting> replicaShardRoutings = new ArrayList<>();
    for (ShardRouting shard : allocation.routingNodes().unassigned()) {
        if (shard.getIndexName().equals(index) && shard.getId() == shardId && shard.primary() == false) {
            replicaShardRoutings.add(shard);
        }
    }
    ShardRouting shardRouting;
    if (replicaShardRoutings.isEmpty()) {
        return explainOrThrowRejectedCommand(explain, allocation, "all copies of [" + index + "][" + shardId + "] are already assigned. Use the move allocation command instead");
    } else {
        shardRouting = replicaShardRoutings.get(0);
    }
    Decision decision = allocation.deciders().canAllocate(shardRouting, routingNode, allocation);
    if (decision.type() == Decision.Type.NO) {
        // don't use explainOrThrowRejectedCommand to keep the original "NO" decision
        if (explain) {
            return new RerouteExplanation(this, decision);
        }
        throw new IllegalArgumentException("[" + name() + "] allocation of [" + index + "][" + shardId + "] on node " + discoNode + " is not allowed, reason: " + decision);
    }
    initializeUnassignedShard(allocation, routingNodes, routingNode, shardRouting);
    return new RerouteExplanation(this, decision);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) ArrayList(java.util.ArrayList) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) RerouteExplanation(org.elasticsearch.cluster.routing.allocation.RerouteExplanation) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision)

Aggregations

Decision (org.elasticsearch.cluster.routing.allocation.decider.Decision)41 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)24 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)18 AllocateUnassignedDecision (org.elasticsearch.cluster.routing.allocation.AllocateUnassignedDecision)18 NodeAllocationResult (org.elasticsearch.cluster.routing.allocation.NodeAllocationResult)16 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)12 ArrayList (java.util.ArrayList)10 UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)10 AllocationDecision (org.elasticsearch.cluster.routing.allocation.AllocationDecision)10 ShardId (org.elasticsearch.index.shard.ShardId)9 ClusterInfo (org.elasticsearch.cluster.ClusterInfo)8 ShardRoutingState (org.elasticsearch.cluster.routing.ShardRoutingState)8 MoveDecision (org.elasticsearch.cluster.routing.allocation.MoveDecision)8 XContentParser (org.elasticsearch.common.xcontent.XContentParser)8 HashMap (java.util.HashMap)7 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)6 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)5 AllocationDeciders (org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders)5 Settings (org.elasticsearch.common.settings.Settings)5 Test (org.junit.Test)5