mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
ctlv3/command: auto compact and defrag after "check perf"
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
1e9ba31eb4
commit
d1e85570e9
@ -33,8 +33,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
checkPerfLoad string
|
||||
checkPerfPrefix string
|
||||
checkPerfLoad string
|
||||
checkPerfPrefix string
|
||||
checkPerfAutoCompact bool
|
||||
checkPerfAutoDefrag bool
|
||||
)
|
||||
|
||||
type checkPerfCfg struct {
|
||||
@ -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
|
||||
}
|
||||
@ -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")
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user