diff --git a/etcdctl/README.md b/etcdctl/README.md index db273ec83..990a3fdcd 100644 --- a/etcdctl/README.md +++ b/etcdctl/README.md @@ -913,7 +913,7 @@ If NOSPACE alarm is present: ### DEFRAG [options] -DEFRAG defragments the backend database file for a set of given endpoints while etcd is running, ~~or directly defragments an etcd data directory while etcd is not running~~. When an etcd member reclaims storage space from deleted and compacted keys, the space is kept in a free list and the database file remains the same size. By defragmenting the database, the etcd member releases this free space back to the file system. +DEFRAG defragments the backend database file for a set of given endpoints while etcd is running. When an etcd member reclaims storage space from deleted and compacted keys, the space is kept in a free list and the database file remains the same size. By defragmenting the database, the etcd member releases this free space back to the file system. **Note: to defragment offline (`--data-dir` flag), use: `etcutl defrag` instead** @@ -921,9 +921,6 @@ DEFRAG defragments the backend database file for a set of given endpoints while **Note that defragmentation request does not get replicated over cluster. That is, the request is only applied to the local node. Specify all members in `--endpoints` flag or `--cluster` flag to automatically find all cluster members.** -#### Options - -- data-dir -- Optional. **Deprecated**. If present, defragments a data directory not in use by etcd. To be removed in v3.6. #### Output @@ -946,16 +943,6 @@ Finished defragmenting etcd member[http://127.0.0.1:22379] Finished defragmenting etcd member[http://127.0.0.1:32379] ``` -To defragment a data directory directly, use the `etcdutl` with `--data-dir` flag -(`etcdctl` will remove this flag in v3.6): - -``` bash -# Defragment while etcd is not running -./etcdutl defrag --data-dir default.etcd -# success (exit status 0) -# Error: cannot open database at default.etcd/member/snap/db -``` - #### Remarks DEFRAG returns a zero exit code only if it succeeded defragmenting all given endpoints. diff --git a/etcdctl/ctlv3/command/defrag_command.go b/etcdctl/ctlv3/command/defrag_command.go index 9b4f29a6a..5ebf4483d 100644 --- a/etcdctl/ctlv3/command/defrag_command.go +++ b/etcdctl/ctlv3/command/defrag_command.go @@ -20,14 +20,9 @@ import ( "time" "github.com/spf13/cobra" - "go.etcd.io/etcd/etcdutl/v3/etcdutl" "go.etcd.io/etcd/pkg/v3/cobrautl" ) -var ( - defragDataDir string -) - // NewDefragCommand returns the cobra command for "Defrag". func NewDefragCommand() *cobra.Command { cmd := &cobra.Command{ @@ -36,19 +31,10 @@ func NewDefragCommand() *cobra.Command { Run: defragCommandFunc, } cmd.PersistentFlags().BoolVar(&epClusterEndpoints, "cluster", false, "use all endpoints from the cluster member list") - cmd.Flags().StringVar(&defragDataDir, "data-dir", "", "Optional. If present, defragments a data directory not in use by etcd.") - cmd.MarkFlagDirname("data-dir") return cmd } func defragCommandFunc(cmd *cobra.Command, args []string) { - if len(defragDataDir) > 0 { - fmt.Fprintf(os.Stderr, "Use `etcdutl defrag` instead. The --data-dir is going to be decomissioned in v3.6.\n\n") - err := etcdutl.DefragData(defragDataDir) - if err != nil { - cobrautl.ExitWithError(cobrautl.ExitError, err) - } - } failures := 0 c := mustClientFromCmd(cmd) diff --git a/tests/e2e/ctl_v3_defrag_test.go b/tests/e2e/ctl_v3_defrag_test.go index 6abf855f4..c47ed3f4c 100644 --- a/tests/e2e/ctl_v3_defrag_test.go +++ b/tests/e2e/ctl_v3_defrag_test.go @@ -22,9 +22,6 @@ import ( func TestCtlV3DefragOnline(t *testing.T) { testCtl(t, defragOnlineTest) } -func TestCtlV3DefragOffline(t *testing.T) { - testCtlWithOffline(t, maintenanceInitKeys, defragOfflineTest) -} func TestCtlV3DefragOfflineEtcdutl(t *testing.T) { testCtlWithOffline(t, maintenanceInitKeys, defragOfflineTest, withEtcdutl()) }