mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #13461 from qsyqian/etcdctl-command-defrag
etcdctl/ctlv3/command: add use time for defrag command
This commit is contained in:
commit
7e0248b367
@ -17,6 +17,7 @@ package command
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"go.etcd.io/etcd/etcdutl/v3/etcdutl"
|
"go.etcd.io/etcd/etcdutl/v3/etcdutl"
|
||||||
@ -53,13 +54,15 @@ func defragCommandFunc(cmd *cobra.Command, args []string) {
|
|||||||
c := mustClientFromCmd(cmd)
|
c := mustClientFromCmd(cmd)
|
||||||
for _, ep := range endpointsFromCluster(cmd) {
|
for _, ep := range endpointsFromCluster(cmd) {
|
||||||
ctx, cancel := commandCtx(cmd)
|
ctx, cancel := commandCtx(cmd)
|
||||||
|
start := time.Now()
|
||||||
_, err := c.Defragment(ctx, ep)
|
_, err := c.Defragment(ctx, ep)
|
||||||
|
d := time.Now().Sub(start)
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Failed to defragment etcd member[%s] (%v)\n", ep, err)
|
fmt.Fprintf(os.Stderr, "Failed to defragment etcd member[%s]. took %s. (%v)\n", ep, d.String(), err)
|
||||||
failures++
|
failures++
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Finished defragmenting etcd member[%s]\n", ep)
|
fmt.Printf("Finished defragmenting etcd member[%s]. took %s\n", ep, d.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user