From 657a197bfa049c6003696248198b0f7717e0c39a Mon Sep 17 00:00:00 2001 From: Kun Zhang Date: Tue, 12 Apr 2022 22:41:50 +0800 Subject: [PATCH] add range flag for delete in etcdctl --- CHANGELOG/CHANGELOG-3.6.md | 1 + etcdctl/ctlv3/command/del_command.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG/CHANGELOG-3.6.md b/CHANGELOG/CHANGELOG-3.6.md index 05bc6c495..320412faa 100644 --- a/CHANGELOG/CHANGELOG-3.6.md +++ b/CHANGELOG/CHANGELOG-3.6.md @@ -12,6 +12,7 @@ See [code changes](https://github.com/etcd-io/etcd/compare/v3.5.0...v3.6.0). - `etcd` will no longer start on data dir created by newer versions (for example etcd v3.6 will not run on v3.7+ data dir). To downgrade data dir please check out `etcdutl migrate` command. - `etcd` doesn't support serving client requests on the peer listen endpoints (--listen-peer-urls). See [pull/13565](https://github.com/etcd-io/etcd/pull/13565). +- `etcdctl` will sleep(2s) in case of range delete without `--range` flag.See [pull/13747](https://github.com/etcd-io/etcd/pull/13747) ### Deprecations diff --git a/etcdctl/ctlv3/command/del_command.go b/etcdctl/ctlv3/command/del_command.go index dbfd186db..9c5298249 100644 --- a/etcdctl/ctlv3/command/del_command.go +++ b/etcdctl/ctlv3/command/del_command.go @@ -16,6 +16,8 @@ package command import ( "fmt" + "os" + "time" "github.com/spf13/cobra" "go.etcd.io/etcd/client/v3" @@ -26,6 +28,7 @@ var ( delPrefix bool delPrevKV bool delFromKey bool + delRange bool ) // NewDelCommand returns the cobra command for "del". @@ -39,6 +42,7 @@ func NewDelCommand() *cobra.Command { cmd.Flags().BoolVar(&delPrefix, "prefix", false, "delete keys with matching prefix") cmd.Flags().BoolVar(&delPrevKV, "prev-kv", false, "return deleted key-value pairs") cmd.Flags().BoolVar(&delFromKey, "from-key", false, "delete keys that are greater than or equal to the given key using byte compare") + cmd.Flags().BoolVar(&delRange, "range", false, "delete range of keys") return cmd } @@ -70,6 +74,11 @@ func getDelOp(args []string) (string, []clientv3.OpOption) { cobrautl.ExitWithError(cobrautl.ExitBadArgs, fmt.Errorf("too many arguments, only accept one argument when `--prefix` or `--from-key` is set")) } opts = append(opts, clientv3.WithRange(args[1])) + if !delRange { + fmt.Fprintf(os.Stderr, "Warning: Keys between %q and %q will be deleted. Please interrupt the command within next 2 seconds to cancel. "+ + "You can provide `--range` flag to avoid the delay.\n", args[0], args[1]) + time.Sleep(2 * time.Second) + } } if delPrefix {