diff --git a/etcdctl/README.md b/etcdctl/README.md index 942d235569f..dd7ae31ab5d 100644 --- a/etcdctl/README.md +++ b/etcdctl/README.md @@ -832,10 +832,14 @@ echo ${transferee_id} ## Concurrency commands -### LOCK \ [command arg1 arg2 ...] +### LOCK [options] \ [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. diff --git a/etcdctl/ctlv3/command/lock_command.go b/etcdctl/ctlv3/command/lock_command.go index e130493f81f..13d3a7c7828 100644 --- a/etcdctl/ctlv3/command/lock_command.go +++ b/etcdctl/ctlv3/command/lock_command.go @@ -28,6 +28,8 @@ import ( "golang.org/x/net/context" ) +var lockTTL = 10 + // NewLockCommand returns the cobra command for "lock". func NewLockCommand() *cobra.Command { c := &cobra.Command{ @@ -35,6 +37,7 @@ func NewLockCommand() *cobra.Command { Short: "Acquires a named lock", Run: lockCommandFunc, } + c.Flags().IntVarP(&lockTTL, "ttl", "", lockTTL, "timeout for session") return c } @@ -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 }