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

Query frontend now discards cached results that are outside of tenant's configured TTL #4439

Merged
merged 8 commits into from
Mar 16, 2023

Conversation

pstibrany
Copy link
Member

@pstibrany pstibrany commented Mar 9, 2023

What this PR does

This PR adds query timestamp into cached results. This allows query-frontend to discard any cached results that are no longer valid due to tenant's configured cache results TTL.

This fixes a problem described in #4383 (comment): changing TTL for cached results used by specific tenant didn't invalidate previously cached results that are now outside of TTL.

All entries cached by previous version of Mimir will be invalidated by this change.

Which issue(s) this PR fixes or relates to

Fixes #4385

Checklist

  • Tests updated
  • [na] Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Copy link
Collaborator

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Good job Peter! The design LGTM. I just left few minor comments.

Comment on lines 383 to 385
// If we don't know the query time, it's too old.
extentsOutOfTTL++
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you considered doing the opposite? If we don't know the QueryTime, then we consider this extent within the TTL. I would avoid loosing all cached query results when rolling out this change. Over time (next 7d?) all cached entries will converge.

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't considered it. It would mean that "per-tenant TTL" feature only starts working correctly 7 days after updating your Mimir installation. On the other hand, people can always flush cache manually, if needed, so I'm fine with that approach too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually keeping extents with QueryTime=0 can prolong their life -- when we merge them with additional extents, we will keep QueryTime=0 and put it back to cache. I guess we could set timestamp of extent in such case. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I've implemented this, but the previous logic was easier to understand, especially when merging multiple extents.

pkg/frontend/querymiddleware/split_and_cache.go Outdated Show resolved Hide resolved
pkg/frontend/querymiddleware/model.proto Outdated Show resolved Hide resolved
When extents are used, we use stored query time to verify if extent can be reused or not.

Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
@pstibrany
Copy link
Member Author

Addressed all feedback in e1e8855

  • renamed QueryTime to query_timestamp_ms
  • keep extents that have query_timestamp_ms == 0, added tests for this case
  • skipping storing extents if len(extents) == 0
  • added getTTLForExtent

Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
@pstibrany pstibrany merged commit 50e11ff into main Mar 16, 2023
@pstibrany pstibrany deleted the add-timestamp-to-extents branch March 16, 2023 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants