Skip to content

Commit

Permalink
Delete lock info when unlocking.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcustodio committed Sep 8, 2017
1 parent b896348 commit b8f4f6d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions backend/remote-state/etcdv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b8f4f6d

Please sign in to comment.