Search in sources :

Example 11 with AllocationDecider

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

the class DecisionsImpactOnClusterHealthTests method testPrimaryShardThrottleDecisionOnIndexCreation.

public void testPrimaryShardThrottleDecisionOnIndexCreation() throws IOException {
    final String indexName = "test-idx";
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString()).build();
    AllocationDecider decider = new TestAllocateDecision(Decision.THROTTLE) {

        // the only allocation decider that implements this is ShardsLimitAllocationDecider and it always
        // returns only YES or NO, never THROTTLE
        @Override
        public Decision canAllocate(RoutingNode node, RoutingAllocation allocation) {
            return randomBoolean() ? Decision.YES : Decision.NO;
        }
    };
    // if deciders THROTTLE allocating a primary shard, stay in YELLOW state
    runAllocationTest(settings, indexName, Collections.singleton(decider), ClusterHealthStatus.YELLOW);
}
Also used : RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) Settings(org.elasticsearch.common.settings.Settings) AllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider)

Example 12 with AllocationDecider

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

the class DecisionsImpactOnClusterHealthTests method testPrimaryShardNoDecisionOnIndexCreation.

public void testPrimaryShardNoDecisionOnIndexCreation() throws IOException {
    final String indexName = "test-idx";
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString()).build();
    AllocationDecider decider = new TestAllocateDecision(Decision.NO);
    // if deciders say NO to allocating a primary shard, then the cluster health should be RED
    runAllocationTest(settings, indexName, Collections.singleton(decider), ClusterHealthStatus.RED);
}
Also used : Settings(org.elasticsearch.common.settings.Settings) AllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider)

Example 13 with AllocationDecider

use of org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider 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)

Aggregations

AllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider)13 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)9 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)8 ClusterState (org.elasticsearch.cluster.ClusterState)7 AllocationDeciders (org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders)6 Settings (org.elasticsearch.common.settings.Settings)6 BalancedShardsAllocator (org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)5 SameShardAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider)3 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)3 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)2 AwarenessAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider)2 ClusterRebalanceAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider)2 ConcurrentRebalanceAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider)2 Decision (org.elasticsearch.cluster.routing.allocation.decider.Decision)2 EnableAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider)2 FilterAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider)2 MaxRetryAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider)2 NodeVersionAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider)2 RebalanceOnlyWhenActiveAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider)2 ReplicaAfterPrimaryActiveAllocationDecider (org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider)2