Skip to content

Fix PolicyStepsRegistry's cachedSteps null handling #84588

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
merged 8 commits into from
Mar 3, 2022

Conversation

joegallo
Copy link
Contributor

@joegallo joegallo commented Mar 2, 2022

Fix for a bug introduced in #82316

In the event that we cache a null (~= "not found") for a given IndexMetadata and StepKey, then subsequent lookups via that same IndexMetadata and StepKey will NPE instead of merely returning null.

As a fix, I've gone with no longer caching nulls paired with asserts that make sure we never find a null in the cache, and that if we put something into the cache we can always pull that exact same thing back out on a subsequent call to getStep getCachedStep with the same arguments.

joegallo added 4 commits March 2, 2022 15:56
Since we're invoking getKey on the cached step (see
cachedStep.v2().getKey() above), the cached step is never allowed to
be null.
To make sure it always works as expected
@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label Mar 2, 2022
@elasticmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @joegallo, I've created a changelog YAML for you.

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

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

LGTM, I left two minor comments, thanks for fixing this.

cachedSteps.put(indexMetadata.getIndex(), Tuple.tuple(indexMetadata, s));
// assert that the cache works as expected -- that is, if we put something into the cache,
// we should get back the same thing if we were to invoke getStep again with the same arguments
assert s == getStep(indexMetadata, stepKey);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think I like this assert, because if the cache were to fail (let's say someone comes along and changes some of the if statements above), then it could end up recursing until a stack overflow. I don't think we need this assert

Copy link
Contributor Author

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 5b9b84c? It makes it non-recursive, so there's no risk of stackoverflow, and also getCachedStep is more clearly read-only w.r.t. the cachedSteps map so this should never modify state.

Copy link
Member

Choose a reason for hiding this comment

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

That looks better to me, no recursion and no chance to modify state in a assert. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Data Management/ILM+SLM Index and Snapshot lifecycle management Team:Data Management Meta label for data/management team v7.17.2 v8.0.2 v8.1.0 v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants