-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Add new "lock" command #619
Conversation
@@ -24,6 +24,11 @@ const ( | |||
// before attempting to do the lock again. This is so that once a lock-delay | |||
// is in affect, we do not hot loop retrying the acquisition. | |||
DefaultLockRetryTime = 5 * time.Second | |||
|
|||
// LockFlagValue is a magic flag we set to indicate a key | |||
// is being used for a semaphore. It is used to detect a potential |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wording just seems reversed here. NBD but confused me.
@armon This looks great! Only minor nit-picks added. Otherwise this LGTM. Glad to see a SIGTERM attempt before SIGKILL in here, too! |
case <-time.After(ttl / 2): | ||
entry, _, err := s.Renew(id, q) | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for a client to believe it holds the lock when it doesn't if this returns with an error? (since we're in a goroutine and not funneling errors down a channel)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both the Lock and Semaphore implementations will catch this and release the lock. e.g. eventually the session gets invalidated, and then they release the lock.
@armon added one more question about |
uses the [leader election algorithm](/docs/guides/leader-election.html). | ||
|
||
If the lock holder count is more than one, then a semaphore is used instead. | ||
A semaphore allows more than a single holder, but the is less efficient than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/the // ?
It would be good to clarify the -n option: if a client A says -n1, client B says -n2, does that mean client B gets in? It'd be good if the number of lock holders is encoded in the lock such that -n2 will block until it wins the lock from an -n1. If that's not possible, then a note in the docs should exist to say that |
layout: "docs" | ||
page_title: "Commands: Lock" | ||
sidebar_current: "docs-commands-lock" | ||
description: |- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @sethvargo mentioned that the description needs to be a single line of text for SEO reasons. You can use >
in place of |-
to do this in YAML.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've fixed this in d478f78
@sean- the |
Thank you!, that looks great. I'm pleasantly impressed and surprised by the fact that this was coded (correctly) in advance. Good forethought and design by whomever. Consul++. |
[sync-catalog] Fix NodePort register service with wrong internal IP when multiple internal IPs are reported on the node
This PR adds a new "consul lock" command. This command can be used to easy do distributed locking for N+1 deploys of highly available services.