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