Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcdctl/check: enable auto compact and defrag for check datascale #9351

Merged
merged 1 commit into from
Feb 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 21 additions & 31 deletions etcdctl/ctlv3/command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import (
var (
checkPerfLoad string
checkPerfPrefix string
checkPerfAutoCompact bool
checkPerfAutoDefrag bool
checkDatascaleLoad string
checkDatascalePrefix string
autoCompact bool
autoDefrag bool
)

type checkPerfCfg struct {
Expand Down Expand Up @@ -126,8 +126,8 @@ func NewCheckPerfCommand() *cobra.Command {
// TODO: support customized configuration
cmd.Flags().StringVar(&checkPerfLoad, "load", "s", "The performance check's workload model. Accepted workloads: s(small), m(medium), l(large), xl(xLarge)")
cmd.Flags().StringVar(&checkPerfPrefix, "prefix", "/etcdctl-check-perf/", "The prefix for writing the performance check's keys.")
cmd.Flags().BoolVar(&checkPerfAutoCompact, "auto-compact", false, "Compact storage with last revision after test is finished.")
cmd.Flags().BoolVar(&checkPerfAutoDefrag, "auto-defrag", false, "Defragment storage after test is finished.")
cmd.Flags().BoolVar(&autoCompact, "auto-compact", false, "Compact storage with last revision after test is finished.")
cmd.Flags().BoolVar(&autoDefrag, "auto-defrag", false, "Defragment storage after test is finished.")

return cmd
}
Expand Down Expand Up @@ -219,11 +219,11 @@ func newCheckPerfCommand(cmd *cobra.Command, args []string) {
ExitWithError(ExitError, err)
}

if checkPerfAutoCompact {
if autoCompact {
compact(clients[0], dresp.Header.Revision)
}

if checkPerfAutoDefrag {
if autoDefrag {
for _, ep := range clients[0].Endpoints() {
defrag(clients[0], ep)
}
Expand Down Expand Up @@ -265,28 +265,6 @@ func newCheckPerfCommand(cmd *cobra.Command, args []string) {
}
}

func compact(c *v3.Client, rev int64) {
fmt.Printf("Compacting with revision %d\n", rev)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, err := c.Compact(ctx, rev, v3.WithCompactPhysical())
cancel()
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("Compacted with revision %d\n", rev)
}

func defrag(c *v3.Client, ep string) {
fmt.Printf("Defragmenting %q\n", ep)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, err := c.Defragment(ctx, ep)
cancel()
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("Defragmented %q\n", ep)
}

// NewCheckDatascaleCommand returns the cobra command for "check datascale".
func NewCheckDatascaleCommand() *cobra.Command {
cmd := &cobra.Command{
Expand All @@ -298,6 +276,8 @@ func NewCheckDatascaleCommand() *cobra.Command {

cmd.Flags().StringVar(&checkDatascaleLoad, "load", "s", "The datascale check's workload model. Accepted workloads: s(small), m(medium), l(large), xl(xLarge)")
cmd.Flags().StringVar(&checkDatascalePrefix, "prefix", "/etcdctl-check-datascale/", "The prefix for writing the datascale check's keys.")
cmd.Flags().BoolVar(&autoCompact, "auto-compact", false, "Compact storage with last revision after test is finished.")
cmd.Flags().BoolVar(&autoDefrag, "auto-defrag", false, "Defragment storage after test is finished.")

return cmd
}
Expand Down Expand Up @@ -389,10 +369,20 @@ func newCheckDatascaleCommand(cmd *cobra.Command, args []string) {

// delete the created kv pairs
ctx, cancel = context.WithCancel(context.Background())
_, err = clients[0].Delete(ctx, checkDatascalePrefix, v3.WithPrefix())
dresp, derr := clients[0].Delete(ctx, checkDatascalePrefix, v3.WithPrefix())
defer cancel()
if err != nil {
ExitWithError(ExitError, err)
if derr != nil {
ExitWithError(ExitError, derr)
}

if autoCompact {
compact(clients[0], dresp.Header.Revision)
}

if autoDefrag {
for _, ep := range clients[0].Endpoints() {
defrag(clients[0], ep)
}
}

if bytesAfter == 0 {
Expand Down
26 changes: 26 additions & 0 deletions etcdctl/ctlv3/command/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"regexp"
"strconv"
"strings"
"time"

v3 "github.com/coreos/etcd/clientv3"
pb "github.com/coreos/etcd/internal/mvcc/mvccpb"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -118,3 +120,27 @@ func endpointMemoryMetrics(host string) float64 {

return residentMemoryBytes
}

// compact keyspace history to a provided revision
func compact(c *v3.Client, rev int64) {
fmt.Printf("Compacting with revision %d\n", rev)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, err := c.Compact(ctx, rev, v3.WithCompactPhysical())
cancel()
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("Compacted with revision %d\n", rev)
}

// defrag a given endpoint
func defrag(c *v3.Client, ep string) {
fmt.Printf("Defragmenting %q\n", ep)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, err := c.Defragment(ctx, ep)
cancel()
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("Defragmented %q\n", ep)
}