Skip to content
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

Do not inject MigrateAction if it is not supported #89457

Merged
merged 9 commits into from
Sep 15, 2022

Conversation

mushao999
Copy link
Contributor

In #61377 we introduced a feature to let ILM migrate data between tiers. We achived this by inject a MigrateAction in warm and cold phase. However we also injected this action to phases where it is not supported such as hot, frozen and delete phase. It's better to no inject MigrateAction even though MigrateAction in these phases will be filtered out in TimeseriesLifecycleType#getOrderedActions(Phase) .
This pr updates the TimeseriesLifecycleType#shouldInjectMigrateStepForPhase(Phase) to not inject MigrateAction for phase in which MigrateAction is not supported.

@elasticsearchmachine elasticsearchmachine added v8.5.0 needs:triage Requires assignment of a team area label external-contributor Pull request authored by a developer outside the Elasticsearch team labels Aug 18, 2022
@DJRickyB DJRickyB added :Data Management/ILM+SLM Index and Snapshot lifecycle management and removed needs:triage Requires assignment of a team area label labels Aug 31, 2022
@elasticsearchmachine elasticsearchmachine added the Team:Data Management Meta label for data/management team label Aug 31, 2022
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@gmarouli gmarouli self-requested a review September 8, 2022 15:20
@gmarouli gmarouli self-assigned this Sep 8, 2022
Copy link
Contributor

@gmarouli gmarouli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mushao999 thank you for discovering and fixing this :)!

summary: Do not inject MigrateAction if it is not supported
area: ILM+SLM
type: enhancement
issues: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the changelog because there is no impact to the user. Even thought the MigrateAction was injected in the beginning it was filtered out later in https://github.com/elastic/elasticsearch/blob/be7c7415627377a1b795400fb8dfcc6cbdf0e322/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java#L239/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChangeLog removed

if (ALLOWED_ACTIONS.get(phase.getName()).contains(MigrateAction.NAME) == false) {
return false;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is public and 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 an IllegalArgumentException like we do in other methods in this class.

Copy link
Contributor Author

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.

Copy link
Contributor

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:

  • We start the method with this:
if (ALLOWED_ACTIONS.containsKey(phase.getName()) == false) {
    throw new IllegalArgumentException("Timeseries lifecycle does not support phase [" + phase.getName() + "]");
}

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 false instead of IllegalArgumentException.

  • Then we could continue listing the phase independent cases, and finally just return if it's allowed in this phase or not:
// if the user configured the {@link MigrateAction} already we won't automatically configure it
if (phase.getActions().get(MigrateAction.NAME) != null) {
    return false;
}
        
// only inject the MigrateAction id it's supported for this phase (for example warm, cold).
return ALLOWED_ACTIONS.get(phase.getName()).contains(MigrateAction.NAME);

What do you think?

Copy link
Contributor Author

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.

Copy link
Contributor

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 IllegalArgumentException if we get an invalid phase?

Copy link
Contributor

@gmarouli gmarouli Sep 14, 2022

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.

Copy link
Contributor

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 false for 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.

Copy link
Contributor

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 false consistently 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! 🚀

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@gmarouli
Copy link
Contributor

gmarouli commented Sep 8, 2022

@elasticmachine ok to test

@gmarouli
Copy link
Contributor

@elasticmachine update branch

@gmarouli
Copy link
Contributor

gmarouli commented Sep 12, 2022

@mushao999, I merged with main so the tests will stop failing. (At least I thought this was the reason).

@gmarouli
Copy link
Contributor

@elasticmachine update branch

Copy link
Contributor

@gmarouli gmarouli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mushao999 , once more thank you for your contribution the swift reactions! It was a pleasure to work on this PR with you!

@gmarouli gmarouli added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Sep 15, 2022
@elasticsearchmachine elasticsearchmachine merged commit 6e4d8bf into elastic:main Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Data Management/ILM+SLM Index and Snapshot lifecycle management external-contributor Pull request authored by a developer outside the Elasticsearch team >refactoring Team:Data Management Meta label for data/management team v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants