Merge pull request #1008 from highlyunavailable/master

Check to see why a lock acquisition failed
This commit is contained in:
Armon Dadgar 2015-06-09 07:59:28 -04:00
commit c2f8f954e2

View File

@ -183,6 +183,17 @@ WAIT:
// Handle the case of not getting the lock // Handle the case of not getting the lock
if !locked { if !locked {
// Determine why the lock failed
qOpts.WaitIndex = 0
pair, meta, err = kv.Get(l.opts.Key, qOpts)
if pair != nil && pair.Session != "" {
//If the session is not null, this means that a wait can safely happen
//using a long poll
qOpts.WaitIndex = meta.LastIndex
goto WAIT
} else {
// If the session is empty and the lock failed to acquire, then it means
// a lock-delay is in effect and a timed wait must be used
select { select {
case <-time.After(DefaultLockRetryTime): case <-time.After(DefaultLockRetryTime):
goto WAIT goto WAIT
@ -190,6 +201,7 @@ WAIT:
return nil, nil return nil, nil
} }
} }
}
HELD: HELD:
// Watch to ensure we maintain leadership // Watch to ensure we maintain leadership