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: use a context with -total-timeout in simple commands #3611

Merged
merged 1 commit into from
Oct 14, 2015
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
5 changes: 3 additions & 2 deletions etcdctl/command/get_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"os"

"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/coreos/etcd/client"
)

Expand All @@ -47,7 +46,9 @@ func getCommandFunc(c *cli.Context, ki client.KeysAPI) {
key := c.Args()[0]
sorted := c.Bool("sort")

resp, err := ki.Get(context.TODO(), key, &client.GetOptions{Sort: sorted})
ctx, cancel := contextWithTotalTimeout(c)
resp, err := ki.Get(ctx, key, &client.GetOptions{Sort: sorted})
cancel()
if err != nil {
handleError(ExitServerError, err)
}
Expand Down
5 changes: 3 additions & 2 deletions etcdctl/command/ls_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"

"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/coreos/etcd/client"
)

Expand Down Expand Up @@ -47,7 +46,9 @@ func lsCommandFunc(c *cli.Context, ki client.KeysAPI) {
sort := c.Bool("sort")
recursive := c.Bool("recursive")

resp, err := ki.Get(context.TODO(), key, &client.GetOptions{Sort: sort, Recursive: recursive})
ctx, cancel := contextWithTotalTimeout(c)
resp, err := ki.Get(ctx, key, &client.GetOptions{Sort: sort, Recursive: recursive})
cancel()
if err != nil {
handleError(ExitServerError, err)
}
Expand Down
5 changes: 3 additions & 2 deletions etcdctl/command/mk_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"time"

"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/coreos/etcd/client"
)

Expand Down Expand Up @@ -51,7 +50,9 @@ func mkCommandFunc(c *cli.Context, ki client.KeysAPI) {

ttl := c.Int("ttl")

resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevIgnore})
ctx, cancel := contextWithTotalTimeout(c)
resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevIgnore})
cancel()
if err != nil {
handleError(ExitServerError, err)
}
Expand Down
5 changes: 3 additions & 2 deletions etcdctl/command/mkdir_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"time"

"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/coreos/etcd/client"
)

Expand All @@ -46,7 +45,9 @@ func mkdirCommandFunc(c *cli.Context, ki client.KeysAPI, prevExist client.PrevEx
key := c.Args()[0]
ttl := c.Int("ttl")

_, err := ki.Set(context.TODO(), key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist})
ctx, cancel := contextWithTotalTimeout(c)
_, err := ki.Set(ctx, key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist})
cancel()
if err != nil {
handleError(ExitServerError, err)
}
Expand Down
5 changes: 3 additions & 2 deletions etcdctl/command/rm_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"errors"

"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/coreos/etcd/client"
)

Expand Down Expand Up @@ -50,7 +49,9 @@ func rmCommandFunc(c *cli.Context, ki client.KeysAPI) {
prevValue := c.String("with-value")
prevIndex := c.Int("with-index")

resp, err := ki.Delete(context.TODO(), key, &client.DeleteOptions{PrevIndex: uint64(prevIndex), PrevValue: prevValue, Dir: dir, Recursive: recursive})
ctx, cancel := contextWithTotalTimeout(c)
resp, err := ki.Delete(ctx, key, &client.DeleteOptions{PrevIndex: uint64(prevIndex), PrevValue: prevValue, Dir: dir, Recursive: recursive})
cancel()
if err != nil {
handleError(ExitServerError, err)
}
Expand Down
5 changes: 3 additions & 2 deletions etcdctl/command/rmdir_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"errors"

"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/coreos/etcd/client"
)

Expand All @@ -40,7 +39,9 @@ func rmdirCommandFunc(c *cli.Context, ki client.KeysAPI) {
}
key := c.Args()[0]

resp, err := ki.Delete(context.TODO(), key, &client.DeleteOptions{Dir: true})
ctx, cancel := contextWithTotalTimeout(c)
resp, err := ki.Delete(ctx, key, &client.DeleteOptions{Dir: true})
cancel()
if err != nil {
handleError(ExitServerError, err)
}
Expand Down
5 changes: 3 additions & 2 deletions etcdctl/command/set_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"time"

"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/coreos/etcd/client"
)

Expand Down Expand Up @@ -55,7 +54,9 @@ func setCommandFunc(c *cli.Context, ki client.KeysAPI) {
prevValue := c.String("swap-with-value")
prevIndex := c.Int("swap-with-index")

resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevIndex: uint64(prevIndex), PrevValue: prevValue})
ctx, cancel := contextWithTotalTimeout(c)
resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevIndex: uint64(prevIndex), PrevValue: prevValue})
cancel()
if err != nil {
handleError(ExitServerError, err)
}
Expand Down
5 changes: 3 additions & 2 deletions etcdctl/command/update_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"time"

"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/coreos/etcd/client"
)

Expand Down Expand Up @@ -51,7 +50,9 @@ func updateCommandFunc(c *cli.Context, ki client.KeysAPI) {

ttl := c.Int("ttl")

resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevExist})
ctx, cancel := contextWithTotalTimeout(c)
resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevExist})
cancel()
if err != nil {
handleError(ExitServerError, err)
}
Expand Down
5 changes: 3 additions & 2 deletions etcdctl/command/update_dir_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"time"

"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/coreos/etcd/client"
)

Expand Down Expand Up @@ -51,7 +50,9 @@ func updatedirCommandFunc(c *cli.Context, ki client.KeysAPI) {

ttl := c.Int("ttl")

_, err = ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: client.PrevExist})
ctx, cancel := contextWithTotalTimeout(c)
_, err = ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: client.PrevExist})
cancel()
if err != nil {
handleError(ExitServerError, err)
}
Expand Down