Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcdctl: add ttl flag for lock command #8370

Merged
merged 1 commit into from
Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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