Skip to content

Allow ingester initialization to continue in background. #2104

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

Closed
wants to merge 1 commit into from
Closed

Allow ingester initialization to continue in background. #2104

wants to merge 1 commit into from

Conversation

pstibrany
Copy link
Contributor

This PR solves problem with slow ingester initialization when doing WAL replays on block databases.

By allowing ingester initialization to continue in the background, the rest of Cortex binary can start in the meantime, especially readiness and metrics handlers. Until ingester initialization has finished, it will return errors to most (but not all, like Flush) API requests.

There may be implications for returning errors from API calls. Alternatively, we can delay registration of handlers until ingester initialization has finished. That would be easy to do, but I'm not sure about the right approach.

Checklist

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

This helps to start the rest of Cortex binary, especially
readiness and metrics handlers. Until ingester initialization
has finished, it will return errors to most (but not all) API
requests.

This solves problem with slow ingester initialization when doing WAL
replays on block databases.

Signed-off-by: Peter Štibraný <[email protected]>
if err != nil {
return
var errfut *ingester.ErrorFuture
t.ingester, errfut = ingester.New(cfg.Ingester, cfg.IngesterClient, t.overrides, t.store, prometheus.DefaultRegisterer)
Copy link
Contributor

Choose a reason for hiding this comment

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

A difference I see is that currently Cortex exits if the initialization fails. After this PR it doesn't and if the ingester initialization fails it will continue to run but not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a valid point, and I can address that.

return
var errfut *ingester.ErrorFuture
t.ingester, errfut = ingester.New(cfg.Ingester, cfg.IngesterClient, t.overrides, t.store, prometheus.DefaultRegisterer)
if done, err := errfut.Get(); done && err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Futures feel needlessly complicated here, and an anti-pattern with Go. Concurrency should be left to the caller, so I believe the module init function should call ingester.New in a goroutine that waits for an error response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that is a valid point. Back to drawing board.

Copy link
Contributor

Choose a reason for hiding this comment

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

However, by contract the ingester should be populated in the Cortex struct once the initIngester() terminates.

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.

3 participants