Merge pull request #13793 from kkkkun/delete-defrag-offline-ctlv3

delete offline defrag in etcdctl
This commit is contained in:
Sahdev Zala 2022-03-15 12:23:54 -04:00 committed by GitHub
commit fa4859f86a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 31 deletions

View File

@ -913,7 +913,7 @@ If NOSPACE alarm is present:
### DEFRAG [options] ### 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** **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.** **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 #### 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] 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 #### Remarks
DEFRAG returns a zero exit code only if it succeeded defragmenting all given endpoints. DEFRAG returns a zero exit code only if it succeeded defragmenting all given endpoints.

View File

@ -20,14 +20,9 @@ import (
"time" "time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.etcd.io/etcd/etcdutl/v3/etcdutl"
"go.etcd.io/etcd/pkg/v3/cobrautl" "go.etcd.io/etcd/pkg/v3/cobrautl"
) )
var (
defragDataDir string
)
// NewDefragCommand returns the cobra command for "Defrag". // NewDefragCommand returns the cobra command for "Defrag".
func NewDefragCommand() *cobra.Command { func NewDefragCommand() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -36,19 +31,10 @@ func NewDefragCommand() *cobra.Command {
Run: defragCommandFunc, Run: defragCommandFunc,
} }
cmd.PersistentFlags().BoolVar(&epClusterEndpoints, "cluster", false, "use all endpoints from the cluster member list") 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 return cmd
} }
func defragCommandFunc(cmd *cobra.Command, args []string) { 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 failures := 0
c := mustClientFromCmd(cmd) c := mustClientFromCmd(cmd)

View File

@ -22,9 +22,6 @@ import (
func TestCtlV3DefragOnline(t *testing.T) { testCtl(t, defragOnlineTest) } func TestCtlV3DefragOnline(t *testing.T) { testCtl(t, defragOnlineTest) }
func TestCtlV3DefragOffline(t *testing.T) {
testCtlWithOffline(t, maintenanceInitKeys, defragOfflineTest)
}
func TestCtlV3DefragOfflineEtcdutl(t *testing.T) { func TestCtlV3DefragOfflineEtcdutl(t *testing.T) {
testCtlWithOffline(t, maintenanceInitKeys, defragOfflineTest, withEtcdutl()) testCtlWithOffline(t, maintenanceInitKeys, defragOfflineTest, withEtcdutl())
} }