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

Make AllocationDecider canRemain loop tighter #86503

Merged
Show file tree
Hide file tree
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 @@ -86,29 +86,44 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl
}
return Decision.NO;
}
Decision.Multi ret = new Decision.Multi();
for (AllocationDecider allocationDecider : allocations) {
Decision decision = allocationDecider.canRemain(shardRouting, node, allocation);
// short track if a NO is returned.
if (decision.type() == Decision.Type.NO) {
if (logger.isTraceEnabled()) {
logger.trace(
"Shard [{}] can not remain on node [{}] due to [{}]",
shardRouting,
node.nodeId(),
allocationDecider.getClass().getSimpleName()
);
}
if (allocation.debugDecision() == false) {
return Decision.NO;
} else {
if (allocation.debugDecision()) {
Decision.Multi ret = new Decision.Multi();
for (AllocationDecider allocationDecider : allocations) {
Decision decision = allocationDecider.canRemain(shardRouting, node, allocation);
// short track if a NO is returned.
if (decision.type() == Decision.Type.NO) {
maybeTraceLogNoDecision(shardRouting, node, allocationDecider);
ret.add(decision);
} else {
addDecision(ret, decision, allocation);
}
} else {
addDecision(ret, decision, allocation);
}
return ret;
} else {
// tighter loop if debug information is not collected: don't collect yes decisions + break out right away on NO
Decision ret = Decision.YES;
for (AllocationDecider allocationDecider : allocations) {
switch (allocationDecider.canRemain(shardRouting, node, allocation).type()) {
case NO -> {
maybeTraceLogNoDecision(shardRouting, node, allocationDecider);
return Decision.NO;
}
case THROTTLE -> ret = Decision.THROTTLE;
}
}
return ret;
}
}

private void maybeTraceLogNoDecision(ShardRouting shardRouting, RoutingNode node, AllocationDecider allocationDecider) {
if (logger.isTraceEnabled()) {
logger.trace(
"Shard [{}] can not remain on node [{}] due to [{}]",
shardRouting,
node.nodeId(),
allocationDecider.getClass().getSimpleName()
);
}
return ret;
}

public Decision canAllocate(IndexMetadata indexMetadata, RoutingNode node, RoutingAllocation allocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ public Decision canRebalance(RoutingAllocation allocation) {
verify(deciders.canAllocate(shardRouting, allocation), matcher);
verify(deciders.canRebalance(shardRouting, allocation), matcher);
verify(deciders.canRebalance(allocation), matcher);
verify(deciders.canRemain(shardRouting, routingNode, allocation), matcher);
final Decision canRemainResult = deciders.canRemain(shardRouting, routingNode, allocation);
if (allocation.debugDecision()) {
verify(canRemainResult, matcher);
} else {
assertSame(canRemainResult, Decision.YES);
}
verify(deciders.canForceAllocatePrimary(shardRouting, routingNode, allocation), matcher);
verify(deciders.shouldAutoExpandToNode(idx, null, allocation), matcher);
}
Expand Down