Skip to content

Commit

Permalink
Merge pull request #8370 from jiaxuanzhou/lock_cmd
Browse files Browse the repository at this point in the history
etcdctl: add ttl flag for lock command
  • Loading branch information
heyitsanthony committed Aug 9, 2017
2 parents 754f454 + 9c21eef commit 0441345
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion etcdctl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,10 +889,14 @@ echo ${transferee_id}

## Concurrency commands

### LOCK \<lockname\> [command arg1 arg2 ...]
### LOCK [options] \<lockname\> [command arg1 arg2 ...]

LOCK acquires a distributed named mutex with a given name. Once the lock is acquired, it will be held until etcdctl is terminated.

#### Options

- ttl - time out in seconds of lock session.

#### Output

Once the lock is acquired, the result for the GET on the unique lock holder key is displayed.
Expand Down
5 changes: 4 additions & 1 deletion etcdctl/ctlv3/command/lock_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ import (
"golang.org/x/net/context"
)

var lockTTL = 10

// NewLockCommand returns the cobra command for "lock".
func NewLockCommand() *cobra.Command {
c := &cobra.Command{
Use: "lock <lockname> [exec-command arg1 arg2 ...]",
Short: "Acquires a named lock",
Run: lockCommandFunc,
}
c.Flags().IntVarP(&lockTTL, "ttl", "", lockTTL, "timeout for session")
return c
}

Expand All @@ -49,7 +52,7 @@ func lockCommandFunc(cmd *cobra.Command, args []string) {
}

func lockUntilSignal(c *clientv3.Client, lockname string, cmdArgs []string) error {
s, err := concurrency.NewSession(c)
s, err := concurrency.NewSession(c, concurrency.WithTTL(lockTTL))
if err != nil {
return err
}
Expand Down

0 comments on commit 0441345

Please sign in to comment.