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: Make Snapshotter a service #8552

Merged
merged 7 commits into from
Jul 9, 2024

Conversation

dimitarvdimitrov
Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov commented Jun 27, 2024

What this PR does

This is the second PR for #8389.

The changes here are:

  1. indexheader.Snapshotter is now a services.Service with a simple timing loop
  2. The BuketStore stops the snapshotter whenever it's shutting down
  3. Make the interval of Snapshotter a hidden configuration flag for easier testing

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.

@dimitarvdimitrov dimitarvdimitrov force-pushed the dimitar/st-gw/snapshotter-service branch from 891c0df to f984b9d Compare June 27, 2024 22:35
@dimitarvdimitrov dimitarvdimitrov force-pushed the dimitar/st-gw/snapshotter-service branch from f984b9d to cad7f4e Compare July 4, 2024 11:33
Base automatically changed from dimitar/st-gw/add-services-to-bucket-stores to main July 4, 2024 18:36
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
@dimitarvdimitrov dimitarvdimitrov force-pushed the dimitar/st-gw/snapshotter-service branch from fb8d68e to 9725277 Compare July 4, 2024 18:37
@dimitarvdimitrov dimitarvdimitrov marked this pull request as ready for review July 4, 2024 18:38
@dimitarvdimitrov dimitarvdimitrov requested a review from a team as a code owner July 4, 2024 18:38
@dimitarvdimitrov
Copy link
Contributor Author

this is now ready for review

pkg/storegateway/indexheader/header.go Show resolved Hide resolved
}

func (s *Snapshotter) PersistLoadedBlocks(bl blocksLoader) error {
func (s *Snapshotter) PersistLoadedBlocks(bl BlocksLoader) error {
Copy link
Contributor

@narqo narqo Jul 5, 2024

Choose a reason for hiding this comment

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

Let's remove the bl argument here and use s.bl that the snapshotter now owns. I can't think of a use-case where someone would want to call the method with a different instance of BlocksLoader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was actually done in the next PR https://github.com/grafana/mimir/pull/8602/files#diff-5b4f5a512e5270de93a5784bedbb0e2b6f9cd3ea3859b072fa25da3651b97116R64-R69

do you mind I don't do it in this PR to save myself from resolving conflicts 🙏 😄

pkg/storegateway/bucket.go Outdated Show resolved Hide resolved
Comment on lines 259 to 263
s.snapshotter = indexheader.NewSnapshotter(s.logger, snapConfig, s.indexReaderPool)
} else {
s.snapshotter = noopShapshotter{services.NewIdleService(nil, nil)}
}
s.indexReaderPool = indexheader.NewReaderPool(s.logger, bucketStoreConfig.IndexHeader, s.lazyLoadingGate, metrics.indexHeaderReaderMetrics, lazyLoadedBlocks)
s.indexReaderPool = indexheader.NewReaderPool(s.logger, bucketStoreConfig.IndexHeader, s.lazyLoadingGate, metrics.indexHeaderReaderMetrics, s.snapshotter.RestoreLoadedBlocks())
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, now I recall this "chicken and an egg", where the Snapshotter takes IndexReader, while the IndexReader needs Snapshotter.

Looking at it now, the Snapshotter.RestoreLoadedBlocks doesn't have to be a method — I made it so mainly to be symmetric to its Snapshotter.PersistLoadedBlocks. How about we make the former a function instead of a (static) method and reorder these constructor calls here to unwind it? This will make it less surprising for a reader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i actually found a bug with the current initialization - we pass a nil to indexheader.NewSnapshotter. It's fixed in the later PR, but it's still a bug here :(

I think I did what you suggested.

pkg/storegateway/bucket.go Show resolved Hide resolved
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>
@dimitarvdimitrov
Copy link
Contributor Author

thanks for the review @narqo. Most of this had gone wrong when I tried splitting my changes into multiple PRs. PTAL 🙏

Copy link
Contributor

@narqo narqo left a comment

Choose a reason for hiding this comment

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

I've left one tiny comment, but resolving it doesn't require a re-review. Looks good to me overall 🔥

pkg/storegateway/bucket.go Outdated Show resolved Hide resolved
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
@dimitarvdimitrov dimitarvdimitrov enabled auto-merge (squash) July 9, 2024 15:50
@dimitarvdimitrov dimitarvdimitrov merged commit 53b4855 into main Jul 9, 2024
29 checks passed
@dimitarvdimitrov dimitarvdimitrov deleted the dimitar/st-gw/snapshotter-service branch July 9, 2024 16:39
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.

2 participants