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

storegateway: improve contention around lazy-loading of blocks #8528

Merged
merged 12 commits into from
Jul 4, 2024

Conversation

narqo
Copy link
Contributor

@narqo narqo commented Jun 26, 2024

What this PR does

These changes are meant to improve the contention around the internal set of blocks in storegateway.BucketStore.

Here, the idea is to rely on sync.Map as a data structure that holds blocks:

The Map type is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex.

Which issue(s) this PR fixes or relates to

Fixes #8258

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

@narqo narqo requested a review from a team as a code owner June 26, 2024 15:02
@narqo narqo marked this pull request as draft June 26, 2024 15:16
@narqo
Copy link
Contributor Author

narqo commented Jun 26, 2024

I moved the changes back to draft. I think we're now allowing a race between (*bucketBlock).Close() and (*bucketBlock).loadedIndexReader(), which was impossible before, due to a long-held lock around s.blocks. Will need to think more on how to resolve that.

@narqo narqo force-pushed the vldmr/gh8258-store-gw-lazy-loading-locks branch 3 times, most recently from 4dfa8cf to 63913f5 Compare June 27, 2024 15:12
@narqo narqo marked this pull request as ready for review June 27, 2024 15:12
@narqo
Copy link
Contributor Author

narqo commented Jun 27, 2024

I think we're now allowing a race between (*bucketBlock).Close() and (*bucketBlock).loadedIndexReader() ...

I believe it's now resolved, and so the PR is ready for review @56quarters @dimitarvdimitrov

Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

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

LGTM with a few small comments. I'd like to here @dimitarvdimitrov's opinion before merging though.

@narqo narqo force-pushed the vldmr/gh8258-store-gw-lazy-loading-locks branch from bdf4151 to 7ec5c11 Compare June 30, 2024 15:37
@dimitarvdimitrov
Copy link
Contributor

sorry for the delay, i'll take a look tomorrow

Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov left a comment

Choose a reason for hiding this comment

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

this makes lazy loading in LabelValues call sequential instead of concurrent. I think we should fix it before merging. Left some other less critical remarks.

@narqo narqo force-pushed the vldmr/gh8258-store-gw-lazy-loading-locks branch from c56260e to 8974c7e Compare July 4, 2024 14:32
@narqo narqo force-pushed the vldmr/gh8258-store-gw-lazy-loading-locks branch from 8974c7e to 5266615 Compare July 4, 2024 14:41
@narqo narqo requested a review from dimitarvdimitrov July 4, 2024 14:43
@narqo
Copy link
Contributor Author

narqo commented Jul 4, 2024

@dimitarvdimitrov I've addressed all the comments. Could you give it another look?

Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@narqo narqo merged commit ae0f259 into main Jul 4, 2024
29 checks passed
@narqo narqo deleted the vldmr/gh8258-store-gw-lazy-loading-locks branch July 4, 2024 15:23
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.

Store-gateway should not hold blocksMx read lock while lazy loading blocks
3 participants