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

ctlv3/command: auto compact and defrag after "check perf" #9330

Merged
merged 1 commit into from
Feb 15, 2018
Merged
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
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)
}