mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #9351 from spzala/compactdefragdatascal
etcdctl/check: enable auto compact and defrag for check datascale
This commit is contained in:
commit
c751fdf5e8
@ -36,10 +36,10 @@ import (
|
|||||||
var (
|
var (
|
||||||
checkPerfLoad string
|
checkPerfLoad string
|
||||||
checkPerfPrefix string
|
checkPerfPrefix string
|
||||||
checkPerfAutoCompact bool
|
|
||||||
checkPerfAutoDefrag bool
|
|
||||||
checkDatascaleLoad string
|
checkDatascaleLoad string
|
||||||
checkDatascalePrefix string
|
checkDatascalePrefix string
|
||||||
|
autoCompact bool
|
||||||
|
autoDefrag bool
|
||||||
)
|
)
|
||||||
|
|
||||||
type checkPerfCfg struct {
|
type checkPerfCfg struct {
|
||||||
@ -126,8 +126,8 @@ func NewCheckPerfCommand() *cobra.Command {
|
|||||||
// TODO: support customized configuration
|
// 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(&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().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(&autoCompact, "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(&autoDefrag, "auto-defrag", false, "Defragment storage after test is finished.")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -219,11 +219,11 @@ func newCheckPerfCommand(cmd *cobra.Command, args []string) {
|
|||||||
ExitWithError(ExitError, err)
|
ExitWithError(ExitError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkPerfAutoCompact {
|
if autoCompact {
|
||||||
compact(clients[0], dresp.Header.Revision)
|
compact(clients[0], dresp.Header.Revision)
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkPerfAutoDefrag {
|
if autoDefrag {
|
||||||
for _, ep := range clients[0].Endpoints() {
|
for _, ep := range clients[0].Endpoints() {
|
||||||
defrag(clients[0], ep)
|
defrag(clients[0], ep)
|
||||||
}
|
}
|
||||||
@ -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".
|
// NewCheckDatascaleCommand returns the cobra command for "check datascale".
|
||||||
func NewCheckDatascaleCommand() *cobra.Command {
|
func NewCheckDatascaleCommand() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
@ -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(&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().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
|
return cmd
|
||||||
}
|
}
|
||||||
@ -389,10 +369,20 @@ func newCheckDatascaleCommand(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
// delete the created kv pairs
|
// delete the created kv pairs
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
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()
|
defer cancel()
|
||||||
if err != nil {
|
if derr != nil {
|
||||||
ExitWithError(ExitError, err)
|
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 {
|
if bytesAfter == 0 {
|
||||||
|
@ -23,7 +23,9 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
v3 "github.com/coreos/etcd/clientv3"
|
||||||
pb "github.com/coreos/etcd/internal/mvcc/mvccpb"
|
pb "github.com/coreos/etcd/internal/mvcc/mvccpb"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -118,3 +120,27 @@ func endpointMemoryMetrics(host string) float64 {
|
|||||||
|
|
||||||
return residentMemoryBytes
|
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)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user