Search in sources :

Example 21 with Decision

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

the class NodeAllocationResultTests method testShardStore.

public void testShardStore() throws IOException {
    DiscoveryNode node = new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    Decision decision = randomFrom(Decision.YES, Decision.THROTTLE, Decision.NO);
    long matchingBytes = (long) randomIntBetween(1, 1000);
    ShardStoreInfo shardStoreInfo = new ShardStoreInfo(matchingBytes);
    NodeAllocationResult explanation = new NodeAllocationResult(node, shardStoreInfo, decision);
    BytesStreamOutput output = new BytesStreamOutput();
    explanation.writeTo(output);
    NodeAllocationResult readExplanation = new NodeAllocationResult(output.bytes().streamInput());
    assertNodeExplanationEquals(explanation, readExplanation);
    assertEquals(matchingBytes, explanation.getShardStoreInfo().getMatchingBytes());
    assertNull(explanation.getShardStoreInfo().getAllocationId());
    assertFalse(explanation.getShardStoreInfo().isInSync());
    assertFalse(explanation.getShardStoreInfo().hasMatchingSyncId());
    String allocId = randomAsciiOfLength(5);
    boolean inSync = randomBoolean();
    shardStoreInfo = new ShardStoreInfo(allocId, inSync, randomBoolean() ? new Exception("bad stuff") : null);
    explanation = new NodeAllocationResult(node, shardStoreInfo, decision);
    output = new BytesStreamOutput();
    explanation.writeTo(output);
    readExplanation = new NodeAllocationResult(output.bytes().streamInput());
    assertNodeExplanationEquals(explanation, readExplanation);
    assertEquals(inSync, explanation.getShardStoreInfo().isInSync());
    assertEquals(-1, explanation.getShardStoreInfo().getMatchingBytes());
    assertFalse(explanation.getShardStoreInfo().hasMatchingSyncId());
    assertEquals(allocId, explanation.getShardStoreInfo().getAllocationId());
}
Also used : ShardStoreInfo(org.elasticsearch.cluster.routing.allocation.NodeAllocationResult.ShardStoreInfo) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) IOException(java.io.IOException)

Example 22 with Decision

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

the class BalancedSingleShardTests method testRebalancingNotAllowedDueToCanRebalance.

public void testRebalancingNotAllowedDueToCanRebalance() {
    final Decision canRebalanceDecision = randomFrom(Decision.NO, Decision.THROTTLE);
    AllocationDecider noRebalanceDecider = new AllocationDecider(Settings.EMPTY) {

        @Override
        public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
            return allocation.decision(canRebalanceDecision, "TEST", "foobar");
        }
    };
    BalancedShardsAllocator allocator = new BalancedShardsAllocator(Settings.EMPTY);
    ClusterState clusterState = ClusterStateCreationUtils.state("idx", randomBoolean(), ShardRoutingState.STARTED);
    ShardRouting shard = clusterState.routingTable().index("idx").shard(0).primaryShard();
    RoutingAllocation routingAllocation = newRoutingAllocation(new AllocationDeciders(Settings.EMPTY, Collections.singleton(noRebalanceDecider)), clusterState);
    MoveDecision rebalanceDecision = allocator.decideShardAllocation(shard, routingAllocation).getMoveDecision();
    assertEquals(canRebalanceDecision.type(), rebalanceDecision.getClusterRebalanceDecision().type());
    assertEquals(AllocationDecision.fromDecisionType(canRebalanceDecision.type()), rebalanceDecision.getAllocationDecision());
    assertThat(rebalanceDecision.getExplanation(), containsString(canRebalanceDecision.type() == Type.THROTTLE ? "rebalancing is throttled" : "rebalancing is not allowed"));
    assertNotNull(rebalanceDecision.getNodeDecisions());
    assertNull(rebalanceDecision.getTargetNode());
    assertEquals(1, rebalanceDecision.getClusterRebalanceDecision().getDecisions().size());
    for (Decision subDecision : rebalanceDecision.getClusterRebalanceDecision().getDecisions()) {
        assertEquals("foobar", ((Decision.Single) subDecision).getExplanation());
    }
    assertAssignedNodeRemainsSame(allocator, routingAllocation, shard);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) AllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider)

Example 23 with Decision

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

the class AllocateUnassignedDecisionTests method testSerialization.

public void testSerialization() throws IOException {
    DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("node2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    Decision.Type finalDecision = randomFrom(Decision.Type.values());
    DiscoveryNode assignedNode = finalDecision == Decision.Type.YES ? node1 : null;
    List<NodeAllocationResult> nodeDecisions = new ArrayList<>();
    nodeDecisions.add(new NodeAllocationResult(node1, Decision.NO, 2));
    nodeDecisions.add(new NodeAllocationResult(node2, finalDecision == Decision.Type.YES ? Decision.YES : randomFrom(Decision.NO, Decision.THROTTLE, Decision.YES), 1));
    AllocateUnassignedDecision decision;
    if (finalDecision == Decision.Type.YES) {
        decision = AllocateUnassignedDecision.yes(assignedNode, randomBoolean() ? randomAsciiOfLength(5) : null, nodeDecisions, randomBoolean());
    } else {
        decision = AllocateUnassignedDecision.no(randomFrom(AllocationStatus.DELAYED_ALLOCATION, AllocationStatus.NO_VALID_SHARD_COPY, AllocationStatus.FETCHING_SHARD_DATA), nodeDecisions, randomBoolean());
    }
    BytesStreamOutput output = new BytesStreamOutput();
    decision.writeTo(output);
    AllocateUnassignedDecision readDecision = new AllocateUnassignedDecision(output.bytes().streamInput());
    assertEquals(decision.getTargetNode(), readDecision.getTargetNode());
    assertEquals(decision.getAllocationStatus(), readDecision.getAllocationStatus());
    assertEquals(decision.getExplanation(), readDecision.getExplanation());
    assertEquals(decision.getNodeDecisions().size(), readDecision.getNodeDecisions().size());
    assertEquals(decision.getAllocationId(), readDecision.getAllocationId());
    assertEquals(decision.getAllocationDecision(), readDecision.getAllocationDecision());
    // node2 should have the highest sort order
    assertEquals("node2", readDecision.getNodeDecisions().iterator().next().getNode().getId());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ArrayList(java.util.ArrayList) Decision(org.elasticsearch.cluster.routing.allocation.decider.Decision) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 24 with Decision

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

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(Settings.EMPTY, Arrays.asList(new TestAllocateDecision(Decision.YES), new SameShardAllocationDecider(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), new AllocationDecider(Settings.EMPTY) {

        @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")).addData(node2, "MATCH", new StoreFileMetaData("file1", 10, "MATCH_CHECKSUM"));
    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) StoreFileMetaData(org.elasticsearch.index.store.StoreFileMetaData) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) RoutingAllocation(org.elasticsearch.cluster.routing.allocation.RoutingAllocation) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) 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 25 with Decision

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

the class SameShardRoutingTests method testForceAllocatePrimaryOnSameNodeNotAllowed.

public void testForceAllocatePrimaryOnSameNodeNotAllowed() {
    SameShardAllocationDecider decider = new SameShardAllocationDecider(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
    ClusterState clusterState = ClusterStateCreationUtils.state("idx", randomIntBetween(2, 4), 1);
    Index index = clusterState.getMetaData().index("idx").getIndex();
    ShardRouting primaryShard = clusterState.routingTable().index(index).shard(0).primaryShard();
    RoutingNode routingNode = clusterState.getRoutingNodes().node(primaryShard.currentNodeId());
    RoutingAllocation routingAllocation = new RoutingAllocation(new AllocationDeciders(Settings.EMPTY, Collections.emptyList()), new RoutingNodes(clusterState, false), clusterState, ClusterInfo.EMPTY, System.nanoTime(), false);
    // can't force allocate same shard copy to the same node
    ShardRouting newPrimary = TestShardRouting.newShardRouting(primaryShard.shardId(), null, true, ShardRoutingState.UNASSIGNED);
    Decision decision = decider.canForceAllocatePrimary(newPrimary, routingNode, routingAllocation);
    assertEquals(Decision.Type.NO, decision.type());
    // can force allocate to a different node
    RoutingNode unassignedNode = null;
    for (RoutingNode node : clusterState.getRoutingNodes()) {
        if (node.isEmpty()) {
            unassignedNode = node;
            break;
        }
    }
    decision = decider.canForceAllocatePrimary(newPrimary, unassignedNode, routingAllocation);
    assertEquals(Decision.Type.YES, decision.type());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) SameShardAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) Index(org.elasticsearch.index.Index) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) 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