Skip to content

Commit

Permalink
Merge branch 'master' into add_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored Oct 13, 2021
2 parents fc40746 + a11bd32 commit fa8f26b
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 70 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ server:

check: fmt lint tidy check-static vet
@# Target: run all checkers. (fmt, lint, tidy, check-static and vet)
$(MAKE) -C components/bench ${MAKECMDGOALS}
$(MAKE) -C components/client ${MAKECMDGOALS}

check-static: tools/bin/golangci-lint
@# Target: run the golangci-lint static check tool
Expand Down Expand Up @@ -119,6 +121,8 @@ clean:

test: failpoint-enable run-tests failpoint-disable
@# Target: run tests with failpoint enabled
$(MAKE) -C components/bench ${MAKECMDGOALS}
$(MAKE) -C components/client ${MAKECMDGOALS}

# TODO: refactor integration tests base on v1 manifest
# run-tests: unit-test integration_test
Expand Down
26 changes: 11 additions & 15 deletions components/bench/ch_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"os"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -32,8 +31,8 @@ func registerCHBenchmark(root *cobra.Command) {
var cmdPrepare = &cobra.Command{
Use: "prepare",
Short: "Prepare data for the workload",
Run: func(cmd *cobra.Command, args []string) {
executeCH("prepare")
RunE: func(cmd *cobra.Command, args []string) error {
return executeCH("prepare")
},
}
cmdPrepare.PersistentFlags().BoolVar(&chConfig.CreateTiFlashReplica,
Expand Down Expand Up @@ -62,21 +61,20 @@ func registerCHBenchmark(root *cobra.Command) {
var cmdRun = &cobra.Command{
Use: "run",
Short: "Run workload",
Run: func(cmd *cobra.Command, _ []string) {
executeCH("run")
RunE: func(cmd *cobra.Command, _ []string) error {
return executeCH("run")
},
}
cmd.AddCommand(cmdRun, cmdPrepare)
root.AddCommand(cmd)
}

func executeCH(action string) {
func executeCH(action string) error {
runtime.GOMAXPROCS(maxProcs)

if err := openDB(); err != nil {
fmt.Println(err)
fmt.Println("Cannot open database, pleae check it (ip/port/username/password)")
os.Exit(1)
return err
}
defer closeDB()

Expand All @@ -92,20 +90,16 @@ func executeCH(action string) {
)
tp, err = tpcc.NewWorkloader(globalDB, &tpccConfig)
if err != nil {
fmt.Printf("Failed to init tp work loader: %v\n", err)
os.Exit(1)
fmt.Println("Failed to init tp work loader")
return err
}
ap = ch.NewWorkloader(globalDB, &chConfig)
if err != nil {
fmt.Printf("Failed to init tp work loader: %v\n", err)
os.Exit(1)
}
timeoutCtx, cancel := context.WithTimeout(globalCtx, totalTime)
defer cancel()

if action == "prepare" {
executeWorkload(timeoutCtx, ap, 1, "prepare")
return
return nil
}

type workLoaderSetting struct {
Expand All @@ -125,4 +119,6 @@ func executeCH(action string) {
for _, workLoader := range []workLoaderSetting{{workLoader: tp, threads: threads}, {workLoader: ap, threads: acThreads}} {
workLoader.workLoader.OutputStats(true)
}

return nil
}
35 changes: 17 additions & 18 deletions components/bench/tpcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
"time"

Expand All @@ -17,18 +16,18 @@ import (

var tpccConfig tpcc.Config

func executeTpcc(action string) {
func executeTpcc(action string) error {
if pprofAddr != "" {
go func() {
http.ListenAndServe(pprofAddr, http.DefaultServeMux)
_ = http.ListenAndServe(pprofAddr, http.DefaultServeMux)
}()
}
runtime.GOMAXPROCS(maxProcs)

if err := openDB(); err != nil {
fmt.Println(err)
fmt.Println("Cannot open database, pleae check it (ip/port/username/password)")
os.Exit(1)
closeDB()
return err
}
defer closeDB()

Expand All @@ -42,17 +41,15 @@ func executeTpcc(action string) {
switch tpccConfig.OutputType {
case "csv", "CSV":
if tpccConfig.OutputDir == "" {
fmt.Printf("Output Directory cannot be empty when generating files")
os.Exit(1)
return fmt.Errorf("Output Directory cannot be empty when generating files")
}
w, err = tpcc.NewCSVWorkloader(globalDB, &tpccConfig)
default:
w, err = tpcc.NewWorkloader(globalDB, &tpccConfig)
}

if err != nil {
fmt.Printf("Failed to init work loader: %v\n", err)
os.Exit(1)
fmt.Println("Failed to init work loader")
return err
}

timeoutCtx, cancel := context.WithTimeout(globalCtx, totalTime)
Expand All @@ -62,6 +59,8 @@ func executeTpcc(action string) {

fmt.Println("Finished")
w.OutputStats(true)

return nil
}

func registerTpcc(root *cobra.Command) {
Expand All @@ -75,8 +74,8 @@ func registerTpcc(root *cobra.Command) {
var cmdPrepare = &cobra.Command{
Use: "prepare",
Short: "Prepare data for TPCC",
Run: func(cmd *cobra.Command, _ []string) {
executeTpcc("prepare")
RunE: func(cmd *cobra.Command, _ []string) error {
return executeTpcc("prepare")
},
}
cmdPrepare.PersistentFlags().BoolVar(&tpccConfig.NoCheck, "no-check", false, "TPCC prepare check, default false")
Expand All @@ -91,8 +90,8 @@ func registerTpcc(root *cobra.Command) {
var cmdRun = &cobra.Command{
Use: "run",
Short: "Run workload",
Run: func(cmd *cobra.Command, _ []string) {
executeTpcc("run")
RunE: func(cmd *cobra.Command, _ []string) error {
return executeTpcc("run")
},
}
cmdRun.PersistentFlags().BoolVar(&tpccConfig.Wait, "wait", false, "including keying & thinking time described on TPC-C Standard Specification")
Expand All @@ -101,16 +100,16 @@ func registerTpcc(root *cobra.Command) {
var cmdCleanup = &cobra.Command{
Use: "cleanup",
Short: "Cleanup data for the workload",
Run: func(cmd *cobra.Command, _ []string) {
executeTpcc("cleanup")
RunE: func(cmd *cobra.Command, _ []string) error {
return executeTpcc("cleanup")
},
}

var cmdCheck = &cobra.Command{
Use: "check",
Short: "Check data consistency for the workload",
Run: func(cmd *cobra.Command, _ []string) {
executeTpcc("check")
RunE: func(cmd *cobra.Command, _ []string) error {
return executeTpcc("check")
},
}

Expand Down
23 changes: 11 additions & 12 deletions components/bench/tpch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"os"
"strings"

"github.com/pingcap/go-tpc/tpch"
Expand All @@ -12,18 +11,17 @@ import (

var tpchConfig tpch.Config

func executeTpch(action string) {
func executeTpch(action string) error {
if err := openDB(); err != nil {
fmt.Println(err)
fmt.Println("Cannot open database, pleae check it (ip/port/username/password)")
os.Exit(1)
closeDB()
return err
}
defer closeDB()

// if globalDB == nil
if globalDB == nil {
fmt.Fprintln(os.Stderr, "cannot connect to the database")
os.Exit(1)
return fmt.Errorf("cannot connect to the database")
}

tpchConfig.DBName = dbName
Expand All @@ -36,6 +34,7 @@ func executeTpch(action string) {
executeWorkload(timeoutCtx, w, threads, action)
fmt.Println("Finished")
w.OutputStats(true)
return nil
}

func registerTpch(root *cobra.Command) {
Expand Down Expand Up @@ -66,8 +65,8 @@ func registerTpch(root *cobra.Command) {
var cmdPrepare = &cobra.Command{
Use: "prepare",
Short: "Prepare data for the workload",
Run: func(cmd *cobra.Command, args []string) {
executeTpch("prepare")
RunE: func(cmd *cobra.Command, args []string) error {
return executeTpch("prepare")
},
}

Expand Down Expand Up @@ -97,16 +96,16 @@ func registerTpch(root *cobra.Command) {
var cmdRun = &cobra.Command{
Use: "run",
Short: "Run workload",
Run: func(cmd *cobra.Command, args []string) {
executeTpch("run")
RunE: func(cmd *cobra.Command, args []string) error {
return executeTpch("run")
},
}

var cmdCleanup = &cobra.Command{
Use: "cleanup",
Short: "Cleanup data for the workload",
Run: func(cmd *cobra.Command, args []string) {
executeTpch("cleanup")
RunE: func(cmd *cobra.Command, args []string) error {
return executeTpch("cleanup")
},
}

Expand Down
6 changes: 5 additions & 1 deletion components/cluster/command/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func newDisplayCmd() *cobra.Command {
clusterName string
showDashboardOnly bool
showVersionOnly bool
showTiKVLabels bool
)
cmd := &cobra.Command{
Use: "display <cluster-name>",
Expand Down Expand Up @@ -74,7 +75,9 @@ func newDisplayCmd() *cobra.Command {
}
return displayDashboardInfo(clusterName, tlsCfg)
}

if showTiKVLabels {
return cm.DisplayTiKVLabels(clusterName, gOpt)
}
return cm.Display(clusterName, gOpt)
},
}
Expand All @@ -84,6 +87,7 @@ func newDisplayCmd() *cobra.Command {
cmd.Flags().BoolVar(&gOpt.ShowUptime, "uptime", false, "Display with uptime")
cmd.Flags().BoolVar(&showDashboardOnly, "dashboard", false, "Only display TiDB Dashboard information")
cmd.Flags().BoolVar(&showVersionOnly, "version", false, "Only display TiDB cluster version")
cmd.Flags().BoolVar(&showTiKVLabels, "labels", false, "Only display labels of specified TiKV role or nodes")
cmd.Flags().BoolVar(&gOpt.JSON, "json", false, "Output in JSON format when applicable")

return cmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/ansible/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func parseGroupVars(dir, ansCfgFile string, clsMeta *spec.ClusterMeta, inv *aini

clsMeta.Topology.Grafanas = append(clsMeta.Topology.Grafanas, tmpIns)
}
log.Infof("Imported %d Grafana node(s).", len(clsMeta.Topology.Alertmanagers))
log.Infof("Imported %d Grafana node(s).", len(clsMeta.Topology.Grafanas))
}

// kafka_exporter_servers
Expand Down
Loading

0 comments on commit fa8f26b

Please sign in to comment.