-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Do not inject MigrateAction if it is not supported #89457
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 9 commits into
elastic:main
from
mushao999:optimize/MigrateAction
Sep 15, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b41121
do not inject MigrateAction if it is not supported
mushao999 d8fc9d8
update test
mushao999 a6c4e25
add changelog
mushao999 51fcaf8
remove the changelog
mushao999 6bebd94
handle invalid phase
mushao999 8ae3668
Merge branch 'main' into optimize/MigrateAction
elasticmachine 990f270
move invalid phase checking to method head
mushao999 ce2b0be
return false for invalid phase
mushao999 c96628e
Merge branch 'main' into optimize/MigrateAction
elasticmachine 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
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.
This method is
publicand can be called with an invalid phase as an argument, if that happens this will throw an NPE. I think we should check this and throw anIllegalArgumentExceptionlike we do in other methods in this class.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.
Good point, I've updated the code in this way.
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.
What do you think about restructuring the conditionals like this:
This way we make sure that we have consistent behaviour every time there is an invalid phase. The way the code is now, if there are searchable snapshots in an invalid phase it will return
falseinstead ofIllegalArgumentException.What do you think?
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 put the invalid-phase-checking there, beacase I want to make the change as smaller as possible.
Moving this checking to the head of this method will change the behaviour of invalid phase who has SearchableSnapshotAction in this method. False would be returned before, but IllegalArgumentException will be thrown for now.
But as you said, we could make sure consistent behaviour for invalid phases in this way which I think is more important for long terms.
I've update the code in this way.
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.
Hm, I see, you are right we are changing the behaviour but I would expect if an invalid phase is provided that it would blow up anyway in a similar way since other methods do that too. I would like to ask another opinion, @dakrone do you see any red flags for throwing an
IllegalArgumentExceptionif we get an invalid phase?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.
Thank for joining the discussion @andreidan , in that case we would be throwing an
NPE, right? Since it's a public method we cannot control that the phase has passed any check.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.
@gmarouli that's correct. I missed we're actually adding the check that uses
ALLOWED_ACTIONS.I think it makes sense to have a check to avoid NPE. IMO returning
falsefor an invalid phase would be preferable - ie. migrate should NOT be injected (as we're not really validating the allowed phases here), but an exception could work too.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.
Great, I am okay with returning
falseconsistently when we receive a phase we do not recognize. @mushao999 if you agree too with this approach, let's replace the exception with returning false and let's ship it! 🚀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.
@gmarouli It's ok for me, code updated.
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.
Thanks! I will merge it with master asap.