-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Refactor MoveDecision method names for clarity #136139
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
Merged
elasticsearchmachine
merged 6 commits into
elastic:main
from
DiannaHohensee:2025/10/07/refactor-MoveDecision-method-names
Oct 30, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bbd6002
Refactor MoveDecision method names for clarity
DiannaHohensee d3d7a24
Merge branch 'main' into 2025/10/07/refactor-MoveDecision-method-names
DiannaHohensee 8df6adc
Merge branch 'main' into 2025/10/07/refactor-MoveDecision-method-names
DiannaHohensee f7562a1
undo canRemainYes to canRemain
DiannaHohensee 198f419
Merge branch 'main' into 2025/10/07/refactor-MoveDecision-method-names
DiannaHohensee d6efcee
updated per Yang review
DiannaHohensee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,11 +92,12 @@ public void writeTo(StreamOutput out) throws IOException { | |
| * Creates a move decision for the shard being able to remain on its current node, so the shard won't | ||
| * be forced to move to another node. | ||
| */ | ||
| public static MoveDecision remain(Decision canRemainDecision) { | ||
| public static MoveDecision createRemainYesDecision(Decision canRemainDecision) { | ||
| assert canRemainDecision.type() != Type.NO; | ||
| assert canRemainDecision.type() != Type.NOT_PREFERRED; | ||
| if (canRemainDecision == Decision.YES) { | ||
| return CACHED_STAY_DECISION; | ||
| } | ||
| assert canRemainDecision.type() != Type.NO; | ||
| return new MoveDecision(null, null, AllocationDecision.NO_ATTEMPT, canRemainDecision, null, 0); | ||
| } | ||
|
|
||
|
|
@@ -150,11 +151,21 @@ public boolean isDecisionTaken() { | |
| * returns {@code false} otherwise. If {@link #isDecisionTaken()} returns {@code false}, | ||
| * then invoking this method will throw an {@code IllegalStateException}. | ||
| */ | ||
| public boolean forceMove() { | ||
| public boolean cannotRemainAndCanMove() { | ||
| checkDecisionState(); | ||
| return canRemain() == false && canMoveDecision == 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. Good call, |
||
|
|
||
| /** | ||
| * Returns {@code true} if the shard cannot remain on its current node and _cannot_ be moved. | ||
| * returns {@code false} otherwise. If {@link #isDecisionTaken()} returns {@code false}, | ||
| * then invoking this method will throw an {@code IllegalStateException}. | ||
| */ | ||
| public boolean cannotRemainAndCannotMove() { | ||
| checkDecisionState(); | ||
| return canRemain() == false && canMoveDecision != AllocationDecision.YES; | ||
| } | ||
|
|
||
| /** | ||
| * Returns {@code true} if the shard can remain on its current node, returns {@code false} otherwise. | ||
| * If {@link #isDecisionTaken()} returns {@code false}, then invoking this method will throw an {@code IllegalStateException}. | ||
|
|
@@ -287,7 +298,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params | |
| builder.field("can_rebalance_to_other_node", canMoveDecision); | ||
| builder.field("rebalance_explanation", getExplanation()); | ||
| } else { | ||
| builder.field("can_move_to_other_node", forceMove() ? "yes" : "no"); | ||
| builder.field("can_move_to_other_node", cannotRemainAndCanMove() ? "yes" : "no"); | ||
| builder.field("move_explanation", getExplanation()); | ||
| } | ||
| return builder; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does
canRemainever returnTHROTTLE, does that even make sense? I wonder why we aren't more specific in this method?Uh oh!
There was an error while loading. Please reload this page.
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.
This is 10 year old code, maybe older. It hasn't been updated in a very long time. I tracked it back to the BalancedShardsAllocator (many refactors), but then gave up :) THROTTLE was added in 2012. This is original Elasticsearch founder code -- i.e. completed quickly, not prettily.
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.
Can we also assert
canRemainDecision.type() != Type.NOT_PREFERRED? Otherwise the method name would be inaccurate.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.
Sure, done