Skip to content

Store phase steps for index in PolicyStepsRegistry#32926

Merged
dakrone merged 9 commits intoelastic:index-lifecyclefrom
dakrone:ilm-only-track-phase-steps
Aug 18, 2018
Merged

Store phase steps for index in PolicyStepsRegistry#32926
dakrone merged 9 commits intoelastic:index-lifecyclefrom
dakrone:ilm-only-track-phase-steps

Conversation

@dakrone
Copy link
Copy Markdown
Member

@dakrone dakrone commented Aug 16, 2018

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 `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
@dakrone dakrone added the :Data Management/ILM+SLM DO NOT USE. Use ":StorageEngine/ILM" or ":Distributed Coordination/SLM" instead. label Aug 16, 2018
@dakrone dakrone requested review from colings86 and talevy August 16, 2018 21:12
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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd love to hear feedback about these tests, whether they should be removed or what?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll investigate removing the firstStepMap, good idea :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After investigating this, removing firstStepMap is much harder than it looks, so I'll leave that for a subsequent PR

@dakrone
Copy link
Copy Markdown
Member Author

dakrone commented Aug 16, 2018

@elasticmachine test this please

Copy link
Copy Markdown
Contributor

@talevy talevy left a comment

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this required?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this necessary given that the Settings.get with default will never have this be null?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

@talevy talevy left a comment

Choose a reason for hiding this comment

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

LGTM

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.
@dakrone
Copy link
Copy Markdown
Member Author

dakrone commented Aug 18, 2018

@elasticmachine test this please

@dakrone dakrone merged commit 77016ad into elastic:index-lifecycle Aug 18, 2018
dakrone added a commit that referenced this pull request Aug 18, 2018
* 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
@dakrone dakrone deleted the ilm-only-track-phase-steps branch February 4, 2019 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Data Management/ILM+SLM DO NOT USE. Use ":StorageEngine/ILM" or ":Distributed Coordination/SLM" instead.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants