-
Notifications
You must be signed in to change notification settings - Fork 25.6k
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
base: main
Are you sure you want to change the base?
Changes from all commits
bbd6002
d3d7a24
8df6adc
f7562a1
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 | ||||
---|---|---|---|---|---|---|
|
@@ -92,11 +92,11 @@ 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 createMoveDecisionWithRemainYesDecision(Decision canRemainDecision) { | ||||||
assert canRemainDecision.type() != Type.NO; | ||||||
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. Does 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. Can we also assert |
||||||
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 +150,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; | ||||||
} | ||||||
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 canRemainDecision.type() != Type.YES && canMoveDecision != AllocationDecision.YES; | ||||||
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. Nit: can we have the check consistent with
Suggested change
|
||||||
} | ||||||
|
||||||
/** | ||||||
* 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 +297,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; | ||||||
|
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.
Nit: I think such a static method name usually skip the type name, e.g.: