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

store-gateway: detect cache key collisions for ExpandedPostings cache #4770

Merged
merged 13 commits into from
Apr 21, 2023

Conversation

dimitarvdimitrov
Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov commented Apr 19, 2023

What this PR does

When storing an ExpandedPostings cache item the key is the hashed matchers from the query. However, we do not check the stored values for cache collisions.

This PR adds cache collisions for ExpandedPostings. It stores the string of the request matchers with the item value and then rechecks it upon retrieval.

To ensure we don't misinterpret some cache item, this PR also changes cache key for expanded postings.

Which issue(s) this PR fixes or relates to

closes #4523

Checklist

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

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
This reverts commit 2e691a7

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
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.

LGTM. I left a couple of comment to suggest to simplify how the read/write offset is handled.

pkg/storegateway/postings_codec.go Outdated Show resolved Hide resolved
pkg/storegateway/postings_codec.go Outdated Show resolved Hide resolved
pkg/storegateway/postings_codec.go Outdated Show resolved Hide resolved
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
@dimitarvdimitrov dimitarvdimitrov changed the title store-gateway: add cache collision for ExpandedPostings cache store-gateway: detect cache key collisions for ExpandedPostings cache Apr 19, 2023
dimitarvdimitrov and others added 2 commits April 20, 2023 18:41
* Add test for postings cache collision

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Implement cache collision for postings

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Update CHANGELOG.md

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Change cache key for postings

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Remove practically unreachable code

* diff-varint-snappy postings are now only used for Series calls
  * this commit moves diffVarintSnappyDecode to testing code
  * removes being able to handle diff-varint-snappy postings without matchers
* since now caching log expects to have some anti-collision material in the cache item,
  we can also remove the handling of raw stored postings. I checked the metric for compression
  failures (cortex_bucket_store_cached_postings_compression_errors_total)
  in the last 30 days across all grafana labs clusters, and it is always 0

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Encode as string

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Avoid sprintf

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* use strings builder

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Update CHANGELOG.md

Co-authored-by: Marco Pracucci <marco@pracucci.com>

---------

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Co-authored-by: Marco Pracucci <marco@pracucci.com>
@pracucci
Copy link
Collaborator

LGTM!

@dimitarvdimitrov dimitarvdimitrov merged commit 7adb11a into main Apr 21, 2023
@dimitarvdimitrov dimitarvdimitrov deleted the dimitar/postings-caching-cache-collisions branch April 21, 2023 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

store-gateway: postings cache is not checked for key hash collisions
2 participants