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