Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow one search shard to fall back to undesired allocation #113847

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private void allocateUnassigned() {
unallocatedStatus = AllocationStatus.NO_ATTEMPT;
} else {
unallocatedStatus = AllocationStatus.DECIDERS_NO;
final var nodeIdsIterator = new NodeIdsIterator(shard, assignment);
final var nodeIdsIterator = new NodeIdsIterator(shard, assignment, routingNodes);
while (nodeIdsIterator.hasNext()) {
final var nodeId = nodeIdsIterator.next();
final var routingNode = routingNodes.node(nodeId);
Expand Down Expand Up @@ -367,7 +367,7 @@ private void allocateUnassigned() {
private final class NodeIdsIterator implements Iterator<String> {

private final ShardRouting shard;

private final RoutingNodes routingNodes;
/**
* Contains the source of the nodeIds used for shard assignment. It could be:
* * desired - when using desired nodes
Expand All @@ -380,8 +380,9 @@ private final class NodeIdsIterator implements Iterator<String> {

private boolean wasThrottled = false;

NodeIdsIterator(ShardRouting shard, ShardAssignment assignment) {
NodeIdsIterator(ShardRouting shard, ShardAssignment assignment, RoutingNodes routingNodes) {
this.shard = shard;
this.routingNodes = routingNodes;

var forcedInitialAllocation = allocation.deciders().getForcedInitialShardAllocationToNodes(shard, allocation);
if (forcedInitialAllocation.isPresent()) {
Expand All @@ -396,7 +397,10 @@ private final class NodeIdsIterator implements Iterator<String> {

@Override
public boolean hasNext() {
if (nodeIds.hasNext() == false && source == NodeIdSource.DESIRED && shard.primary() && wasThrottled == false) {
if (nodeIds.hasNext() == false
&& source == NodeIdSource.DESIRED
&& wasThrottled == false
&& useFallback(shard, routingNodes)) {
var fallbackNodeIds = allocation.routingNodes().getAllNodeIds();
logger.debug("Shard [{}] assignment is temporarily not possible. Falling back to {}", shard.shardId(), fallbackNodeIds);
nodeIds = allocationOrdering.sort(fallbackNodeIds).iterator();
Expand All @@ -405,6 +409,19 @@ public boolean hasNext() {
return nodeIds.hasNext();
}

private boolean useFallback(ShardRouting shard, RoutingNodes routingNodes) {
if (shard.primary()) {
return true;
}
if (shard.role().equals(ShardRouting.Role.SEARCH_ONLY)) {
// Allow only one search shard to fall back to allocation to an undesired node
return routingNodes.assignedShards(shard.shardId())
.stream()
.noneMatch(s -> s.role().equals(ShardRouting.Role.SEARCH_ONLY));
}
return false;
}

@Override
public String next() {
return nodeIds.next();
Expand Down