Search in sources :

Example 1 with ShardAllocationDecision

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

the class TransportClusterAllocationExplainAction method explainShard.

// public for testing
public static ClusterAllocationExplanation explainShard(ShardRouting shardRouting, RoutingAllocation allocation, ClusterInfo clusterInfo, boolean includeYesDecisions, GatewayAllocator gatewayAllocator, ShardsAllocator shardAllocator) {
    allocation.setDebugMode(includeYesDecisions ? DebugMode.ON : DebugMode.EXCLUDE_YES_DECISIONS);
    ShardAllocationDecision shardDecision;
    if (shardRouting.initializing() || shardRouting.relocating()) {
        shardDecision = ShardAllocationDecision.NOT_TAKEN;
    } else {
        AllocateUnassignedDecision allocateDecision = shardRouting.unassigned() ? gatewayAllocator.decideUnassignedShardAllocation(shardRouting, allocation) : AllocateUnassignedDecision.NOT_TAKEN;
        if (allocateDecision.isDecisionTaken() == false) {
            shardDecision = shardAllocator.decideShardAllocation(shardRouting, allocation);
        } else {
            shardDecision = new ShardAllocationDecision(allocateDecision, MoveDecision.NOT_TAKEN);
        }
    }
    return new ClusterAllocationExplanation(shardRouting, shardRouting.currentNodeId() != null ? allocation.nodes().get(shardRouting.currentNodeId()) : null, shardRouting.relocatingNodeId() != null ? allocation.nodes().get(shardRouting.relocatingNodeId()) : null, clusterInfo, shardDecision);
}
Also used : AllocateUnassignedDecision(org.elasticsearch.cluster.routing.allocation.AllocateUnassignedDecision) ShardAllocationDecision(org.elasticsearch.cluster.routing.allocation.ShardAllocationDecision)

Example 2 with ShardAllocationDecision

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

the class ClusterAllocationExplanationTests method randomClusterAllocationExplanation.

private static ClusterAllocationExplanation randomClusterAllocationExplanation(boolean assignedShard) {
    ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId(new Index("idx", "123"), 0), assignedShard ? "node-0" : null, true, assignedShard ? ShardRoutingState.STARTED : ShardRoutingState.UNASSIGNED);
    DiscoveryNode node = assignedShard ? new DiscoveryNode("node-0", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT) : null;
    ShardAllocationDecision shardAllocationDecision;
    if (assignedShard) {
        MoveDecision moveDecision = MoveDecision.cannotRebalance(Decision.YES, AllocationDecision.NO, 3, null).withRemainDecision(Decision.YES);
        shardAllocationDecision = new ShardAllocationDecision(AllocateUnassignedDecision.NOT_TAKEN, moveDecision);
    } else {
        AllocateUnassignedDecision allocateDecision = AllocateUnassignedDecision.no(UnassignedInfo.AllocationStatus.DECIDERS_NO, null);
        shardAllocationDecision = new ShardAllocationDecision(allocateDecision, MoveDecision.NOT_TAKEN);
    }
    return new ClusterAllocationExplanation(shardRouting, node, null, null, shardAllocationDecision);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MoveDecision(org.elasticsearch.cluster.routing.allocation.MoveDecision) Index(org.elasticsearch.index.Index) AllocateUnassignedDecision(org.elasticsearch.cluster.routing.allocation.AllocateUnassignedDecision) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) ShardAllocationDecision(org.elasticsearch.cluster.routing.allocation.ShardAllocationDecision)

Example 3 with ShardAllocationDecision

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

the class ClusterAllocationExplainActionTests method testInitializingOrRelocatingShardExplanation.

public void testInitializingOrRelocatingShardExplanation() throws Exception {
    ShardRoutingState shardRoutingState = randomFrom(ShardRoutingState.INITIALIZING, ShardRoutingState.RELOCATING);
    ClusterState clusterState = ClusterStateCreationUtils.state("idx", randomBoolean(), shardRoutingState);
    ShardRouting shard = clusterState.getRoutingTable().index("idx").shard(0).primaryShard();
    RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Settings.EMPTY, Collections.emptyList()), clusterState.getRoutingNodes(), clusterState, null, System.nanoTime(), randomBoolean());
    ClusterAllocationExplanation cae = TransportClusterAllocationExplainAction.explainShard(shard, allocation, null, randomBoolean(), new TestGatewayAllocator(), new ShardsAllocator() {

        @Override
        public void allocate(RoutingAllocation allocation) {
        // no-op
        }

        @Override
        public ShardAllocationDecision decideShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
            if (shard.initializing() || shard.relocating()) {
                return ShardAllocationDecision.NOT_TAKEN;
            } else {
                throw new UnsupportedOperationException("cannot explain");
            }
        }
    });
    assertEquals(shard.currentNodeId(), cae.getCurrentNode().getId());
    assertFalse(cae.getShardAllocationDecision().isDecisionTaken());
    assertFalse(cae.getShardAllocationDecision().getAllocateDecision().isDecisionTaken());
    assertFalse(cae.getShardAllocationDecision().getMoveDecision().isDecisionTaken());
    XContentBuilder builder = XContentFactory.jsonBuilder();
    cae.toXContent(builder, ToXContent.EMPTY_PARAMS);
    String explanation;
    if (shardRoutingState == ShardRoutingState.RELOCATING) {
        explanation = "the shard is in the process of relocating from node [] to node [], wait until " + "relocation has completed";
    } else {
        explanation = "the shard is in the process of initializing on node [], " + "wait until initialization has completed";
    }
    assertEquals("{\"index\":\"idx\",\"shard\":0,\"primary\":true,\"current_state\":\"" + shardRoutingState.toString().toLowerCase(Locale.ROOT) + "\",\"current_node\":" + "{\"id\":\"" + cae.getCurrentNode().getId() + "\",\"name\":\"" + cae.getCurrentNode().getName() + "\",\"transport_address\":\"" + cae.getCurrentNode().getAddress() + "\"},\"explanation\":\"" + explanation + "\"}", builder.string());
}
Also used : TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) ClusterState(org.elasticsearch.cluster.ClusterState) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation) ShardAllocationDecision(org.elasticsearch.cluster.routing.allocation.ShardAllocationDecision) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 4 with ShardAllocationDecision

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

the class BalancedShardsAllocator method decideShardAllocation.

@Override
public ShardAllocationDecision decideShardAllocation(final ShardRouting shard, final RoutingAllocation allocation) {
    Balancer balancer = new Balancer(logger, allocation, weightFunction, threshold);
    AllocateUnassignedDecision allocateUnassignedDecision = AllocateUnassignedDecision.NOT_TAKEN;
    MoveDecision moveDecision = MoveDecision.NOT_TAKEN;
    if (shard.unassigned()) {
        allocateUnassignedDecision = balancer.decideAllocateUnassigned(shard, Sets.newHashSet());
    } else {
        moveDecision = balancer.decideMove(shard);
        if (moveDecision.isDecisionTaken() && moveDecision.canRemain()) {
            MoveDecision rebalanceDecision = balancer.decideRebalance(shard);
            moveDecision = rebalanceDecision.withRemainDecision(moveDecision.getCanRemainDecision());
        }
    }
    return new ShardAllocationDecision(allocateUnassignedDecision, moveDecision);
}
Also used : MoveDecision(org.elasticsearch.cluster.routing.allocation.MoveDecision) AllocateUnassignedDecision(org.elasticsearch.cluster.routing.allocation.AllocateUnassignedDecision) ShardAllocationDecision(org.elasticsearch.cluster.routing.allocation.ShardAllocationDecision)

Aggregations

ShardAllocationDecision (org.elasticsearch.cluster.routing.allocation.ShardAllocationDecision)4 AllocateUnassignedDecision (org.elasticsearch.cluster.routing.allocation.AllocateUnassignedDecision)3 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)2 MoveDecision (org.elasticsearch.cluster.routing.allocation.MoveDecision)2 ClusterState (org.elasticsearch.cluster.ClusterState)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 ShardRoutingState (org.elasticsearch.cluster.routing.ShardRoutingState)1 TestShardRouting (org.elasticsearch.cluster.routing.TestShardRouting)1 RoutingAllocation (org.elasticsearch.cluster.routing.allocation.RoutingAllocation)1 ShardsAllocator (org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator)1 AllocationDeciders (org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 Index (org.elasticsearch.index.Index)1 ShardId (org.elasticsearch.index.shard.ShardId)1 TestGatewayAllocator (org.elasticsearch.test.gateway.TestGatewayAllocator)1