From e36c499d0f738be106d540bc291e0126a910239e Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Tue, 11 Aug 2015 13:33:50 -0700 Subject: [PATCH] etcdctl: add per request timeout --- etcdctl/command/get_command.go | 1 - etcdctl/command/ls_command.go | 1 - etcdctl/command/mk_command.go | 1 - etcdctl/command/mkdir_command.go | 1 - etcdctl/command/rm_command.go | 1 - etcdctl/command/rmdir_command.go | 1 - etcdctl/command/set_command.go | 1 - etcdctl/command/update_command.go | 1 - etcdctl/command/update_dir_command.go | 1 - etcdctl/command/util.go | 5 +++-- etcdctl/main.go | 2 ++ 11 files changed, 5 insertions(+), 11 deletions(-) diff --git a/etcdctl/command/get_command.go b/etcdctl/command/get_command.go index 63923d2f6..3ab23dfe8 100644 --- a/etcdctl/command/get_command.go +++ b/etcdctl/command/get_command.go @@ -47,7 +47,6 @@ func getCommandFunc(c *cli.Context, ki client.KeysAPI) { key := c.Args()[0] sorted := c.Bool("sort") - // TODO: handle transport timeout resp, err := ki.Get(context.TODO(), key, &client.GetOptions{Sort: sorted}) if err != nil { handleError(ExitServerError, err) diff --git a/etcdctl/command/ls_command.go b/etcdctl/command/ls_command.go index bfb1c9ebb..47f1c0c33 100644 --- a/etcdctl/command/ls_command.go +++ b/etcdctl/command/ls_command.go @@ -47,7 +47,6 @@ func lsCommandFunc(c *cli.Context, ki client.KeysAPI) { sort := c.Bool("sort") recursive := c.Bool("recursive") - // TODO: handle transport timeout resp, err := ki.Get(context.TODO(), key, &client.GetOptions{Sort: sort, Recursive: recursive}) if err != nil { handleError(ExitServerError, err) diff --git a/etcdctl/command/mk_command.go b/etcdctl/command/mk_command.go index 412d89fa0..7ab41d060 100644 --- a/etcdctl/command/mk_command.go +++ b/etcdctl/command/mk_command.go @@ -51,7 +51,6 @@ func mkCommandFunc(c *cli.Context, ki client.KeysAPI) { ttl := c.Int("ttl") - // TODO: handle transport timeout resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevIgnore}) if err != nil { handleError(ExitServerError, err) diff --git a/etcdctl/command/mkdir_command.go b/etcdctl/command/mkdir_command.go index f5f92eac1..dbf5fdcc1 100644 --- a/etcdctl/command/mkdir_command.go +++ b/etcdctl/command/mkdir_command.go @@ -46,7 +46,6 @@ func mkdirCommandFunc(c *cli.Context, ki client.KeysAPI, prevExist client.PrevEx key := c.Args()[0] ttl := c.Int("ttl") - // TODO: handle transport timeout _, err := ki.Set(context.TODO(), key, "", &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: prevExist}) if err != nil { handleError(ExitServerError, err) diff --git a/etcdctl/command/rm_command.go b/etcdctl/command/rm_command.go index c0c127e9b..212b1eb6e 100644 --- a/etcdctl/command/rm_command.go +++ b/etcdctl/command/rm_command.go @@ -50,7 +50,6 @@ func rmCommandFunc(c *cli.Context, ki client.KeysAPI) { prevValue := c.String("with-value") prevIndex := c.Int("with-index") - // TODO: handle transport timeout resp, err := ki.Delete(context.TODO(), key, &client.DeleteOptions{PrevIndex: uint64(prevIndex), PrevValue: prevValue, Dir: dir, Recursive: recursive}) if err != nil { handleError(ExitServerError, err) diff --git a/etcdctl/command/rmdir_command.go b/etcdctl/command/rmdir_command.go index 3c8b68bb5..62a88a58a 100644 --- a/etcdctl/command/rmdir_command.go +++ b/etcdctl/command/rmdir_command.go @@ -40,7 +40,6 @@ func rmdirCommandFunc(c *cli.Context, ki client.KeysAPI) { } key := c.Args()[0] - // TODO: handle transport timeout resp, err := ki.Delete(context.TODO(), key, &client.DeleteOptions{Dir: true}) if err != nil { handleError(ExitServerError, err) diff --git a/etcdctl/command/set_command.go b/etcdctl/command/set_command.go index 3673d33cb..f077634ed 100644 --- a/etcdctl/command/set_command.go +++ b/etcdctl/command/set_command.go @@ -55,7 +55,6 @@ func setCommandFunc(c *cli.Context, ki client.KeysAPI) { prevValue := c.String("swap-with-value") prevIndex := c.Int("swap-with-index") - // TODO: handle transport timeout resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevIndex: uint64(prevIndex), PrevValue: prevValue}) if err != nil { handleError(ExitServerError, err) diff --git a/etcdctl/command/update_command.go b/etcdctl/command/update_command.go index 27b8d53e9..c9a68ce3f 100644 --- a/etcdctl/command/update_command.go +++ b/etcdctl/command/update_command.go @@ -51,7 +51,6 @@ func updateCommandFunc(c *cli.Context, ki client.KeysAPI) { ttl := c.Int("ttl") - // TODO: handle transport timeout resp, err := ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevExist}) if err != nil { handleError(ExitServerError, err) diff --git a/etcdctl/command/update_dir_command.go b/etcdctl/command/update_dir_command.go index a6e16bad8..08b2c9a43 100644 --- a/etcdctl/command/update_dir_command.go +++ b/etcdctl/command/update_dir_command.go @@ -51,7 +51,6 @@ func updatedirCommandFunc(c *cli.Context, ki client.KeysAPI) { ttl := c.Int("ttl") - // TODO: handle transport timeout _, err = ki.Set(context.TODO(), key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, Dir: true, PrevExist: client.PrevExist}) if err != nil { handleError(ExitServerError, err) diff --git a/etcdctl/command/util.go b/etcdctl/command/util.go index 8c2e4a3ac..e213bea90 100644 --- a/etcdctl/command/util.go +++ b/etcdctl/command/util.go @@ -188,8 +188,9 @@ func mustNewClient(c *cli.Context) client.Client { } cfg := client.Config{ - Transport: tr, - Endpoints: eps, + Transport: tr, + Endpoints: eps, + HeaderTimeoutPerRequest: c.GlobalDuration("timeout"), } uFlag := c.GlobalString("username") diff --git a/etcdctl/main.go b/etcdctl/main.go index f67cf5f42..8c8703593 100644 --- a/etcdctl/main.go +++ b/etcdctl/main.go @@ -16,6 +16,7 @@ package main import ( "os" + "time" "github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli" "github.com/coreos/etcd/etcdctl/command" @@ -37,6 +38,7 @@ func main() { cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"}, cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"}, cli.StringFlag{Name: "username, u", Value: "", Usage: "provide username[:password] and prompt if password is not supplied."}, + cli.DurationFlag{Name: "timeout", Value: time.Second, Usage: "connection timeout per request"}, } app.Commands = []cli.Command{ command.NewBackupCommand(),