瀏覽代碼

etcdctl: add ttl flag for lock command

Zhou 8 年之前
父節點
當前提交
9c21eefd09
共有 2 個文件被更改,包括 9 次插入2 次删除
  1. 5 1
      etcdctl/README.md
  2. 4 1
      etcdctl/ctlv3/command/lock_command.go

+ 5 - 1
etcdctl/README.md

@@ -832,10 +832,14 @@ echo ${transferee_id}
 
 
 ## Concurrency commands
 ## 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.
 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
 #### Output
 
 
 Once the lock is acquired, the result for the GET on the unique lock holder key is displayed.
 Once the lock is acquired, the result for the GET on the unique lock holder key is displayed.

+ 4 - 1
etcdctl/ctlv3/command/lock_command.go

@@ -28,6 +28,8 @@ import (
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
 )
 )
 
 
+var lockTTL = 10
+
 // NewLockCommand returns the cobra command for "lock".
 // NewLockCommand returns the cobra command for "lock".
 func NewLockCommand() *cobra.Command {
 func NewLockCommand() *cobra.Command {
 	c := &cobra.Command{
 	c := &cobra.Command{
@@ -35,6 +37,7 @@ func NewLockCommand() *cobra.Command {
 		Short: "Acquires a named lock",
 		Short: "Acquires a named lock",
 		Run:   lockCommandFunc,
 		Run:   lockCommandFunc,
 	}
 	}
+	c.Flags().IntVarP(&lockTTL, "ttl", "", lockTTL, "timeout for session")
 	return c
 	return c
 }
 }
 
 
@@ -49,7 +52,7 @@ func lockCommandFunc(cmd *cobra.Command, args []string) {
 }
 }
 
 
 func lockUntilSignal(c *clientv3.Client, lockname string, cmdArgs []string) error {
 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 {
 	if err != nil {
 		return err
 		return err
 	}
 	}