Skip to content

Commit

Permalink
Merge pull request #9330 from gyuho/auto-compact-defrag
Browse files Browse the repository at this point in the history
ctlv3/command: auto compact and defrag after "check perf"
  • Loading branch information
gyuho authored Feb 15, 2018
2 parents 1e9ba31 + d1e8557 commit b03fd4c
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions etcdctl/ctlv3/command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import (
)

var (
checkPerfLoad string
checkPerfPrefix string
checkPerfLoad string
checkPerfPrefix string
checkPerfAutoCompact bool
checkPerfAutoDefrag bool
)

type checkPerfCfg struct {
Expand Down Expand Up @@ -90,6 +92,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.")

return cmd
}
Expand Down Expand Up @@ -175,12 +179,22 @@ func newCheckPerfCommand(cmd *cobra.Command, args []string) {
s := <-sc

ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
_, err = clients[0].Delete(ctx, checkPerfPrefix, v3.WithPrefix())
dresp, err := clients[0].Delete(ctx, checkPerfPrefix, v3.WithPrefix())
cancel()
if err != nil {
ExitWithError(ExitError, err)
}

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

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

ok = true
if len(s.ErrorDist) != 0 {
fmt.Println("FAIL: too many errors")
Expand Down Expand Up @@ -216,3 +230,25 @@ func newCheckPerfCommand(cmd *cobra.Command, args []string) {
os.Exit(ExitError)
}
}

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)
}

0 comments on commit b03fd4c

Please sign in to comment.