-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Undo not-preferred in allocation explain #140195
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,34 +118,15 @@ public static MoveDecision move( | |
| ) { | ||
| assert canRemainDecision != null; | ||
| assert canRemainDecision.type() != Type.YES : "create decision with MoveDecision#createRemainYesDecision instead"; | ||
| assert decisionAndTargetAreConsistent(canRemainDecision, moveDecision, targetNode) | ||
| : "targetNode: " + targetNode + ", move decision: " + moveDecision; | ||
| if (nodeDecisions == null && moveDecision == AllocationDecision.NO) { | ||
| // the final decision is NO (no node to move the shard to) and we are not in explain mode, return a cached version | ||
| return CACHED_CANNOT_MOVE_DECISION; | ||
| } else { | ||
| assert ((targetNode == null) == (moveDecision != AllocationDecision.YES)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From here |
||
| return new MoveDecision(targetNode, nodeDecisions, moveDecision, canRemainDecision, null, 0); | ||
| } | ||
| } | ||
|
|
||
| private static boolean decisionAndTargetAreConsistent( | ||
| Decision canRemainDecision, | ||
| AllocationDecision moveDecision, | ||
| DiscoveryNode targetNode | ||
| ) { | ||
| return switch (moveDecision) { | ||
| // YES must always have a target | ||
| case AllocationDecision.YES -> (targetNode != null); | ||
| case AllocationDecision.NOT_PREFERRED -> { | ||
| // If canRemain is not-preferred, then there should be no shard move, and thus no target node. | ||
| assert (canRemainDecision.type() == Type.NOT_PREFERRED) == (targetNode == null) | ||
| : "remain decision: " + canRemainDecision + ", target node: " + targetNode; | ||
| yield true; | ||
| } | ||
| default -> targetNode == null; | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a decision for whether to move the shard to a different node to form a better cluster balance. | ||
| */ | ||
|
|
@@ -282,29 +263,23 @@ public String getExplanation() { | |
| ? Explanations.Rebalance.CANNOT_REBALANCE_CAN_ALLOCATE | ||
| : Explanations.Rebalance.CANNOT_REBALANCE_CANNOT_ALLOCATE; | ||
| case THROTTLE -> Explanations.Rebalance.CLUSTER_THROTTLE; | ||
| case YES -> { | ||
| case YES, NOT_PREFERRED -> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From here |
||
| if (getTargetNode() != null) { | ||
| yield canMoveDecision == AllocationDecision.THROTTLED | ||
| ? Explanations.Rebalance.NODE_THROTTLE | ||
| : Explanations.Rebalance.YES; | ||
| } else { | ||
| yield canMoveDecision == AllocationDecision.NOT_PREFERRED | ||
| ? Explanations.Rebalance.NOT_PREFERRED | ||
| : Explanations.Rebalance.ALREADY_BALANCED; | ||
| yield Explanations.Rebalance.ALREADY_BALANCED; | ||
| } | ||
| } | ||
| case NOT_PREFERRED -> Explanations.Rebalance.NOT_PREFERRED; | ||
| }; | ||
| } else { | ||
| // it was a decision by an allocation decider to move the shard | ||
| assert cannotRemain(); | ||
| return switch (canMoveDecision) { | ||
| case YES -> canRemainNotPreferred() ? Explanations.Move.NOT_PREFERRED_TO_YES : Explanations.Move.YES; | ||
| case NOT_PREFERRED -> canRemainNotPreferred() | ||
| ? Explanations.Move.NOT_PREFERRED_TO_NOT_PREFERRED | ||
| : Explanations.Move.NOT_PREFERRED; | ||
| case THROTTLED -> canRemainNotPreferred() ? Explanations.Move.NOT_PREFERRED_TO_THROTTLED : Explanations.Move.THROTTLED; | ||
| case NO -> canRemainNotPreferred() ? Explanations.Move.NOT_PREFERRED_TO_NO : Explanations.Move.NO; | ||
| case YES, NOT_PREFERRED -> Explanations.Move.YES; | ||
| case THROTTLED -> Explanations.Move.THROTTLED; | ||
| case NO -> Explanations.Move.NO; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From here |
||
| case WORSE_BALANCE, AWAITING_INFO, ALLOCATION_DELAYED, NO_VALID_SHARD_COPY, NO_ATTEMPT -> { | ||
| assert false : canMoveDecision; | ||
| yield canMoveDecision.toString(); | ||
|
|
@@ -341,13 +316,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params | |
| builder.field("can_rebalance_to_other_node", canMoveDecision); | ||
| builder.field("rebalance_explanation", getExplanation()); | ||
| } else { | ||
| if (cannotRemainAndCanMove()) { | ||
| builder.field("can_move_to_other_node", "yes"); | ||
| } else if (cannotRemainAndNotPreferredMove()) { | ||
| builder.field("can_move_to_other_node", "not-preferred"); | ||
| } else { | ||
| builder.field("can_move_to_other_node", "no"); | ||
| } | ||
| builder.field("can_move_to_other_node", cannotRemainAndCanMove() ? "yes" : "no"); | ||
| builder.field("move_explanation", getExplanation()); | ||
| } | ||
| return builder; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -531,15 +531,10 @@ private MoveDecision explainRebalanceDecision(final ProjectIndex index, final Sh | |
| // with the shard remaining on the current node, and we are allowed to allocate to the | ||
| // node in question, then allow the rebalance | ||
| if (rebalanceConditionsMet && canAllocate.type().higherThan(bestRebalanceCanAllocateDecisionType)) { | ||
| // Overwrite the best decision since it is better than the last. This means that YES/THROTTLE decisions will replace | ||
| // NOT_PREFERRED/NO decisions, and a YES decision will replace a THROTTLE decision. NOT_PREFERRED will also replace | ||
| // NO, even if neither are acted upon for rebalancing, for allocation explain purposes. | ||
| // rebalance to the node, only will get overwritten if the decision here is to | ||
| // THROTTLE and we get a decision with YES on another node | ||
| bestRebalanceCanAllocateDecisionType = canAllocate.type(); | ||
| if (canAllocate.type().higherThan(Type.NOT_PREFERRED)) { | ||
| // Movement is only allowed to THROTTLE/YES nodes. NOT_PREFERRED is the same as no for rebalancing, since | ||
| // rebalancing aims to distribute resource usage and NOT_PREFERRED means the move could cause hot-spots. | ||
| targetNode = node; | ||
| } | ||
| targetNode = node; | ||
|
Comment on lines
+534
to
+537
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From here |
||
| } | ||
| } | ||
| Tuple<ModelNode, Decision> nodeResult = Tuple.tuple(node, canAllocate); | ||
|
|
@@ -1047,12 +1042,10 @@ private MoveDecision decideMove( | |
| nodeResults.add(new NodeAllocationResult(currentNode.getRoutingNode().node(), allocationDecision, ++weightRanking)); | ||
| } | ||
| if (allocationDecision.type() == Type.NOT_PREFERRED && remainDecision.type() == Type.NOT_PREFERRED) { | ||
| // Whether or not a relocation target node can be found, it's important to explain the canAllocate response as | ||
| // NOT_PREFERRED, as opposed to NO. | ||
| bestDecision = Type.NOT_PREFERRED; | ||
| // Relocating a shard from one NOT_PREFERRED node to another NOT_PREFERRED node would not improve the situation. | ||
| // Relocating a shard from one NOT_PREFERRED node to another would not improve the situation. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From here |
||
| continue; | ||
| } | ||
|
|
||
| if (allocationDecision.type().higherThan(bestDecision)) { | ||
| bestDecision = allocationDecision.type(); | ||
| if (bestDecision == Type.YES) { | ||
|
|
@@ -1064,12 +1057,8 @@ private MoveDecision decideMove( | |
| } | ||
| } else if (bestDecision == Type.NOT_PREFERRED) { | ||
| assert remainDecision.type() != Type.NOT_PREFERRED; | ||
| // If we don't ever find a YES/THROTTLE decision, we'll settle for NOT_PREFERRED as preferable to NO. | ||
| // If we don't ever find a YES decision, we'll settle for NOT_PREFERRED as preferable to NO. | ||
| targetNode = target; | ||
| } else if (bestDecision == Type.THROTTLE) { | ||
| assert allocation.isSimulating() == false; | ||
| // THROTTLE is better than NOT_PREFERRED, we just need to wait for a YES. | ||
| targetNode = null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From here |
||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From here.
The TODO comment isn't right, but presumably this is temporary.