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

databroker: implement leases #2172

Merged
merged 4 commits into from
May 10, 2021
Merged

databroker: implement leases #2172

merged 4 commits into from
May 10, 2021

Conversation

calebdoxsey
Copy link
Contributor

Summary

This is a distributed mutex algorithm implementing using leases with TTLs. This allows multiple databrokers with only one identity manager loop.

The flow is:

  1. acquire a lease
  2. call the handler with a cancelable context
  3. periodically renew the lease. If this fails, cancel the context.
  4. If the parent context hasn't been canceled, try to acquire the lease

If the lease can't be acquired the Leaser will just keep retrying every ttl/2.

The backend implements leasing via a single method that can be called in 3 ways:

  1. The initial lease is created by using a new UUID.
  2. Renewal is implemented by re-using the UUID for the lease id. The TTL will then be updated.
  3. Release is implemented by using a TTL of 0.

The redis implementation uses a watch+transaction to ensure atomicity.

Checklist

  • reference any related issues
  • updated docs
  • updated unit tests
  • updated UPGRADING.md
  • add appropriate tag (improvement / bug / etc)
  • ready for review

@calebdoxsey calebdoxsey requested a review from a team as a code owner May 3, 2021 22:42
@calebdoxsey calebdoxsey requested a review from wasaga May 3, 2021 22:42
@codeclimate
Copy link

codeclimate bot commented May 3, 2021

Code Climate has analyzed commit 4f3463b and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

Copy link
Contributor

@wasaga wasaga left a comment

Choose a reason for hiding this comment

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

looks great

@calebdoxsey
Copy link
Contributor Author

I updated the code to retry on gRPC errors. I also added some tests.

@calebdoxsey calebdoxsey merged commit 94aa0b1 into master May 10, 2021
@calebdoxsey calebdoxsey deleted the cdoxsey/334-lock branch May 10, 2021 19:30
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.

None yet

3 participants