Browse Source

api: Minor cleanups in lock

pull/600/head
Armon Dadgar 10 years ago
parent
commit
c291acd96e
  1. 6
      api/lock.go

6
api/lock.go

@ -70,6 +70,9 @@ func (c *Client) LockKey(key string) (*Lock, error) {
// to acquire and release the mutex. The key used must have // to acquire and release the mutex. The key used must have
// write permissions. // write permissions.
func (c *Client) LockOpts(opts *LockOptions) (*Lock, error) { func (c *Client) LockOpts(opts *LockOptions) (*Lock, error) {
if opts.Key == "" {
return nil, fmt.Errorf("missing key")
}
if opts.SessionName == "" { if opts.SessionName == "" {
opts.SessionName = DefaultLockSessionName opts.SessionName = DefaultLockSessionName
} }
@ -264,17 +267,16 @@ func (l *Lock) renewSession(id string, doneCh chan struct{}) {
// monitorLock is a long running routine to monitor a lock ownership // monitorLock is a long running routine to monitor a lock ownership
// It closes the stopCh if we lose our leadership. // It closes the stopCh if we lose our leadership.
func (l *Lock) monitorLock(session string, stopCh chan struct{}) { func (l *Lock) monitorLock(session string, stopCh chan struct{}) {
defer close(stopCh)
kv := l.c.KV() kv := l.c.KV()
opts := &QueryOptions{RequireConsistent: true} opts := &QueryOptions{RequireConsistent: true}
WAIT: WAIT:
pair, meta, err := kv.Get(l.opts.Key, opts) pair, meta, err := kv.Get(l.opts.Key, opts)
if err != nil { if err != nil {
close(stopCh)
return return
} }
if pair != nil && pair.Session == session { if pair != nil && pair.Session == session {
opts.WaitIndex = meta.LastIndex opts.WaitIndex = meta.LastIndex
goto WAIT goto WAIT
} }
close(stopCh)
} }

Loading…
Cancel
Save