-
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
Changes from 2 commits
bbd6002
d3d7a24
8df6adc
f7562a1
198f419
d6efcee
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; | ||||||
|
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. Does
Contributor
Author
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.
Member
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
Contributor
Author
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. Sure, done |
||||||
| 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,16 +150,26 @@ 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 canRemainYes() == 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; | ||||||
| return canRemainDecision.type() != Type.YES && canMoveDecision != AllocationDecision.YES; | ||||||
|
||||||
| return canRemainDecision.type() != Type.YES && canMoveDecision != AllocationDecision.YES; | |
| return canRemain() == false && canMoveDecision != AllocationDecision.YES; |
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.
Done
Outdated
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 change does not seem necessary to me. The Yes part is quite obviously implied for a boolean method.
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.
I got tripped up by the name, so if it doesn't cause any harm, it'd be nice to make the purpose extra clear.
The fact that the method returns a boolean, and not a canRemain decision, was one point of confusion that this change hopefully clarifies. The other is that there are more decisions than NO and YES these days (THROTTLE, NOT_PREFERRED), so the change further clarifies why the shard should/can stay.
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.
I'm also less excited about this change, it seems to break encapsulation for me. For whatever reason we have a MoveDecision and it boils canRemain down to a boolean. The canRemainDecision seems like an implementation detail? and one the caller shouldn't care about?
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.
... it boils canRemain down to a boolean. ... and one the caller shouldn't care about?
I'm not convinced these are good arguments for the status quo, since the interface is old and inconsistent and could easily be handing back a number of types for canRemain other than a boolean (and what does the boolean mean?), but I'll change it back.
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.:
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.
Updated to
createRemainYesDecision.