Unlock takes key and token and tries to unlock the key. It redirects the request to the partition owner, if required.
(ctx context.Context, key string, token []byte)
| 72 | // Unlock takes key and token and tries to unlock the key. |
| 73 | // It redirects the request to the partition owner, if required. |
| 74 | func (dm *DMap) Unlock(ctx context.Context, key string, token []byte) error { |
| 75 | hkey := partitions.HKey(dm.name, key) |
| 76 | member := dm.s.primary.PartitionByHKey(hkey).Owner() |
| 77 | if member.CompareByName(dm.s.rt.This()) { |
| 78 | return dm.unlockKey(ctx, key, token) |
| 79 | } |
| 80 | |
| 81 | cmd := protocol.NewUnlock(dm.name, key, hex.EncodeToString(token)).Command(dm.s.ctx) |
| 82 | rc := dm.s.client.Get(member.String()) |
| 83 | err := rc.Process(ctx, cmd) |
| 84 | if err != nil { |
| 85 | return protocol.ConvertError(err) |
| 86 | } |
| 87 | return protocol.ConvertError(cmd.Err()) |
| 88 | } |
| 89 | |
| 90 | // tryLock takes a deadline and env and sets a key-value pair by using |
| 91 | // Put with NX and PX commands. It tries to acquire the lock 100 times per second |