Store phase steps for index in PolicyStepsRegistry#32926
Store phase steps for index in PolicyStepsRegistry#32926dakrone merged 9 commits intoelastic:index-lifecyclefrom
Conversation
This changes the way that steps are retrieved from `PolicyStepsRegistry` to store the steps on a per-index basis (in memory for now, though that will change in subsequent PRs). These steps are rebuilt as the index changes phases. This also fixes a bug where an action with the same phase and name was not being considered changed (and thus updated) in the compiled steps list. These are now correctly considered as "upsert" diffs. Relates to elastic#29823
| assertThat(LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newState.metaData().index(index).getSettings()), equalTo("")); | ||
| } | ||
|
|
||
| // TODO: I think these tests are invalid now that policy name is not used for retrieving the step |
There was a problem hiding this comment.
I'd love to hear feedback about these tests, whether they should be removed or what?
There was a problem hiding this comment.
hmm. I think part of the problem is that I do not think we need a firstStepMap anymore? Since we can see our index is just initializing when we update the policy-registry and seed the indexPhaseSteps with the Steps from the first phase and just retrieve the first item in the list from there when asked for getFirstStep.
There was a problem hiding this comment.
I'll investigate removing the firstStepMap, good idea :)
There was a problem hiding this comment.
After investigating this, removing firstStepMap is much harder than it looks, so I'll leave that for a subsequent PR
|
@elasticmachine test this please |
talevy
left a comment
There was a problem hiding this comment.
looks great! I left a few questions and comments that I hope we can iterate on. We may find some not important, while others cause a few further internal changes to the PolicyStepsRegistry's data-structures
| actions.put(action.getWriteableName(), action); | ||
| } | ||
| String phaseName = randomAlphaOfLength(10); | ||
| String phaseName = randomFrom(TimeseriesLifecycleType.VALID_PHASES); |
There was a problem hiding this comment.
I don't think so any more, I'll revert
|
|
||
| @SuppressWarnings({ "unchecked", "rawtypes" }) | ||
| public void update(IndexLifecycleMetadata meta, Client client, LongSupplier nowSupplier) { | ||
| public void update(ClusterState clusterState, IndexLifecycleMetadata meta, Client client, LongSupplier nowSupplier) { |
There was a problem hiding this comment.
should we break up this update method into its underlying parts of the MetaData that it is concerned with? Also fine with leaving it as is, just feels big and difficult to juggle which we're updating
There was a problem hiding this comment.
I think that's a good idea, but not yet. The next parts of this refactor are going to be touching this method quite a bit, so I don't think it makes sense to split it up quite yet
| "_none_" : currentSteps.get(0).getKey().getPhase(); | ||
| // Retrieve the current phase, defaulting to "new" if no phase is set | ||
| final String currentPhase = imd.value.getSettings().get(LifecycleSettings.LIFECYCLE_PHASE, "new"); | ||
| assert currentPhase != null : "expected a current phase but it was null"; |
There was a problem hiding this comment.
is this necessary given that the Settings.get with default will never have this be null?
There was a problem hiding this comment.
I think this was a holdover from before I added the default return value for the setting retrieval, I'll remove it
| assertThat(LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newState.metaData().index(index).getSettings()), equalTo("")); | ||
| } | ||
|
|
||
| // TODO: I think these tests are invalid now that policy name is not used for retrieving the step |
There was a problem hiding this comment.
hmm. I think part of the problem is that I do not think we need a firstStepMap anymore? Since we can see our index is just initializing when we update the policy-registry and seed the indexPhaseSteps with the Steps from the first phase and just retrieve the first item in the list from there when asked for getFirstStep.
|
|
||
| // TODO: I think these tests are invalid now that policy name is not used for retrieving the step | ||
| @AwaitsFix(bugUrl = "fix me") | ||
| public void testExecuteInvalidStartStep() throws IOException { |
There was a problem hiding this comment.
I think this just needs to be made more general and not just test what it means to be an invalid first step, but an invalid step in general? I don't see other "invalid" input tests here and this was at least one of them
| } | ||
|
|
||
| @AwaitsFix(bugUrl = "fix me") | ||
| public void testExecuteUntilNullStep() throws IOException { |
There was a problem hiding this comment.
I think the check that we hit the end of our Step.nextStepKey == null check can be added to the end of testExecuteAllUntilEndOfPhase
If we go that extra step in the execution in that test, we can get rid of this one
Also switch to using Index rather than String for the map key, this means that a deleted and re-created index will not use the same phase policy steps as an old index.
|
@elasticmachine test this please |
* Store phase steps for index in PolicyStepsRegistry This changes the way that steps are retrieved from `PolicyStepsRegistry` to store the steps on a per-index basis (in memory for now, though that will change in subsequent PRs). These steps are rebuilt as the index changes phases. This also fixes a bug where an action with the same phase and name was not being considered changed (and thus updated) in the compiled steps list. These are now correctly considered as "upsert" diffs. Relates to #29823
This changes the way that steps are retrieved from
PolicyStepsRegistrytostore the steps on a per-index basis (in memory for now, though that will change
in subsequent PRs). These steps are rebuilt as the index changes phases.
This also fixes a bug where an action with the same phase and name was not being
considered changed (and thus updated) in the compiled steps list. These are now
correctly considered as "upsert" diffs.
Relates to #29823