Delete lock info when unlocking.

This commit is contained in:
Bruno Miguel Custodio 2017-09-08 15:21:06 +01:00
parent b896348230
commit b8f4f6d3e2
No known key found for this signature in database
GPG Key ID: 84CDD9E18A1A6B2C
1 changed files with 14 additions and 0 deletions

View File

@ -116,6 +116,17 @@ func (c *RemoteClient) Unlock(id string) error {
return c.unlock(id)
}
func (c *RemoteClient) deleteLockInfo(info *state.LockInfo) error {
res, err := c.Client.KV.Delete(context.TODO(), c.Key+lockInfoSuffix)
if err != nil {
return err
}
if res.Deleted == 0 {
return fmt.Errorf("No keys deleted for %s when deleting lock info.", c.Key+lockInfoSuffix)
}
return nil
}
func (c *RemoteClient) getLockInfo() (*state.LockInfo, error) {
res, err := c.Client.KV.Get(context.TODO(), c.Key+lockInfoSuffix)
if err != nil {
@ -181,6 +192,9 @@ func (c *RemoteClient) unlock(id string) error {
var errs error
if err := c.deleteLockInfo(c.info); err != nil {
errs = multierror.Append(errs, err)
}
if err := c.etcdMutex.Unlock(context.TODO()); err != nil {
errs = multierror.Append(errs, err)
}