mirror of
https://github.com/hashicorp/vault.git
synced 2026-04-22 14:48:40 -04:00
Add require consistent flag to Consul Lock
This commit is contained in:
parent
430e125f45
commit
3aef68a32d
1 changed files with 16 additions and 7 deletions
|
|
@ -367,9 +367,10 @@ func (c *ConsulBackend) LockWith(key, value string) (Lock, error) {
|
|||
return nil, fmt.Errorf("failed to create lock: %v", err)
|
||||
}
|
||||
cl := &ConsulLock{
|
||||
client: c.client,
|
||||
key: c.path + key,
|
||||
lock: lock,
|
||||
client: c.client,
|
||||
key: c.path + key,
|
||||
lock: lock,
|
||||
requireConsistent: c.requireConsistent,
|
||||
}
|
||||
return cl, nil
|
||||
}
|
||||
|
|
@ -396,9 +397,10 @@ func (c *ConsulBackend) DetectHostAddr() (string, error) {
|
|||
|
||||
// ConsulLock is used to provide the Lock interface backed by Consul
|
||||
type ConsulLock struct {
|
||||
client *api.Client
|
||||
key string
|
||||
lock *api.Lock
|
||||
client *api.Client
|
||||
key string
|
||||
lock *api.Lock
|
||||
requireConsistent bool
|
||||
}
|
||||
|
||||
func (c *ConsulLock) Lock(stopCh <-chan struct{}) (<-chan struct{}, error) {
|
||||
|
|
@ -412,7 +414,14 @@ func (c *ConsulLock) Unlock() error {
|
|||
func (c *ConsulLock) Value() (bool, string, error) {
|
||||
kv := c.client.KV()
|
||||
|
||||
pair, _, err := kv.Get(c.key, nil)
|
||||
var queryOptions *api.QueryOptions
|
||||
if c.requireConsistent {
|
||||
queryOptions = &api.QueryOptions{
|
||||
RequireConsistent: c.requireConsistent,
|
||||
}
|
||||
}
|
||||
|
||||
pair, _, err := kv.Get(c.key, queryOptions)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue