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

ring: Add DoUntilQuorum method #293

Merged
merged 13 commits into from
May 15, 2023
Merged

Conversation

charleskorn
Copy link
Contributor

@charleskorn charleskorn commented May 11, 2023

What this PR does:

This PR adds a DoUntilQuorum method to the ring package.

In contrast to the existing ReplicationSet.Do method, DoUntilQuorum has the following behaviour differences:

  • DoUntilQuorum does not support delaying invocations of f
  • DoUntilQuorum supports cleaning up results that will not be returned, including results that arrive after DoUntilQuorum returns, making it easier to ensure that resources are not leaked
  • DoUntilQuorum immediately cancels the context passed to f for any invocations we know will are no longer necessary (eg. because other calls in the same zone have already failed)
  • DoUntilQuorum does not cancel the context passed to f if the result is returned, which is useful for scenarios where DoUntilQuorum is used to establish a set of streams that will continue after DoUntilQuorum returns
  • DoUntilQuorum only returns the minimum set of results required for quorum

This last point is best explained with an example. Imagine we have three zones each with two instances, we tolerate one unavailable zone and the results from each instance arrive in this order:

  1. zone A, instance 1
  2. zone B, instance 1
  3. zone C, instance 1
  4. zone A, instance 2
  5. zone B, instance 2

ReplicationSet.Do would return results from all five instances, whereas DoUntilQuorum will only return the results from the instances in zones A and B and cleanup the results from zone C, including the result from instance 2 in zone C if it arrives.

Which issue(s) this PR fixes:

(none)

Checklist

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

@charleskorn charleskorn requested review from pracucci and codesome May 11, 2023 07:34
@charleskorn charleskorn marked this pull request as ready for review May 11, 2023 07:34
@charleskorn
Copy link
Contributor Author

I've added an example of how this would be used to Mimir: grafana/mimir@70e788c

@aknuds1 aknuds1 added the enhancement New feature or request label May 12, 2023
Copy link
Contributor

@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.

Great job, LGTM! I just left minor comments.

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.

Looks good, only one comment about avoiding allocations when we don't use context tracking.

@pracucci
Copy link
Contributor

Still LGTM! Thanks for addressing feedback.

@charleskorn charleskorn merged commit 05bd0f2 into main May 15, 2023
@charleskorn charleskorn deleted the charleskorn/do-until-quorum branch May 15, 2023 04:33
trevorwhitney added a commit to grafana/loki that referenced this pull request Aug 23, 2023
This changes the forGivenIngestors function in
pkg/querier/ingester_querier.go to use `DoUntilQuorum` (from [PR
#293](grafana/dskit#293)) instead of `Do`.

`DoUntilQuorum` is much more efficient than `Do`. The exact differences
between them can be seen
[here](grafana/dskit#293).

---------

Co-authored-by: Trevor Whitney <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants