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);
}
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);
}
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));
}
Aggregations