Skip to content

Commit

Permalink
add flag of ttl for lock cmd
Browse files Browse the repository at this point in the history
modify flag to --ttl and add options for lock in etcdct,README
  • Loading branch information
Zhou committed Aug 8, 2017
1 parent 366f538 commit aae9e97
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 @@ -832,10 +832,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 aae9e97

Please sign in to comment.