From 5199ebbeecbbf94e8d6d045db5510a6da2ca233c Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger <60744015+Lloyd-Pottiger@users.noreply.github.com> Date: Mon, 10 Oct 2022 18:14:33 +0800 Subject: [PATCH] support add multiple tiflash replica (#148) * support add multiple tiflash replica Signed-off-by: Lloyd-Pottiger * fix typo in README Signed-off-by: Lloyd-Pottiger * address comments Signed-off-by: Lloyd-Pottiger Signed-off-by: Lloyd-Pottiger Co-authored-by: dbsid --- README.md | 6 +++--- ch/workload.go | 22 +++++++++++----------- cmd/go-tpc/ch_benchmark.go | 8 ++++---- cmd/go-tpc/tpch.go | 8 ++++---- tpch/ddl.go | 4 ++-- tpch/workload.go | 20 ++++++++++---------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index a1750c4..4fb53b5 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ If you want to import tpcc data into TiDB, please refer to [import-to-tidb](docs # Prepare data with scale factor 1 ./bin/go-tpc tpch --sf=1 prepare # Prepare data with scale factor 1, create tiflash replica, and analyze table after data loaded -./bin/go-tpc tpch --sf 1 --analyze --tiflash prepare +./bin/go-tpc tpch --sf 1 --analyze --tiflash-replica 1 prepare ``` ##### PostgreSQL & CockroachDB & AlloyDB & Yugabyte @@ -170,9 +170,9 @@ A detail example to run CH workload on TiDB can be refered to [TiDB Doc](https:/ ##### TiDB & MySQL ```bash # Prepare TP data -./bin/go-tpc tpcc --warehouses 10 run -T 4 +./bin/go-tpc tpcc --warehouses 10 prepare -T 4 -D test -H 127.0.0.1 -P 4000 # Prepare AP data, create tiflash replica, and analyze table after data loaded -./bin/go-tpc ch --analyze --tiflash prepare +./bin/go-tpc ch --analyze --tiflash-replica 1 prepare -D test -H 127.0.0.1 -P 4000 ``` ##### PostgreSQL & CockroachDB & AlloyDB & Yugabyte diff --git a/ch/workload.go b/ch/workload.go index e21c88a..b09381d 100644 --- a/ch/workload.go +++ b/ch/workload.go @@ -30,13 +30,13 @@ type analyzeConfig struct { // Config is the configuration for ch workload type Config struct { - Driver string - DBName string - RawQueries string - QueryNames []string - CreateTiFlashReplica bool - AnalyzeTable analyzeConfig - RefreshConnWait time.Duration + Driver string + DBName string + RawQueries string + QueryNames []string + TiFlashReplica int + AnalyzeTable analyzeConfig + RefreshConnWait time.Duration EnablePlanReplayer bool PlanReplayerConfig replayer.PlanReplayerConfig @@ -130,8 +130,8 @@ func (w *Workloader) Prepare(ctx context.Context, threadID int) error { return err } - if w.cfg.CreateTiFlashReplica { - if err := w.createTiFlashReplica(ctx, s); err != nil { + if w.cfg.TiFlashReplica != 0 { + if err := w.createTiFlashReplica(ctx, s, w.cfg.TiFlashReplica); err != nil { return err } } @@ -161,10 +161,10 @@ create view revenue1 (supplier_no, total_revenue) as ( return nil } -func (w *Workloader) createTiFlashReplica(ctx context.Context, s *chState) error { +func (w *Workloader) createTiFlashReplica(ctx context.Context, s *chState, numberOfTiflashReplica int) error { for _, tableName := range allTables { fmt.Printf("creating tiflash replica for %s\n", tableName) - replicaSQL := fmt.Sprintf("ALTER TABLE %s SET TIFLASH REPLICA 1", tableName) + replicaSQL := fmt.Sprintf("ALTER TABLE %s SET TIFLASH REPLICA %d", tableName, numberOfTiflashReplica) if _, err := s.Conn.ExecContext(ctx, replicaSQL); err != nil { return err } diff --git a/cmd/go-tpc/ch_benchmark.go b/cmd/go-tpc/ch_benchmark.go index 21f221a..677be08 100644 --- a/cmd/go-tpc/ch_benchmark.go +++ b/cmd/go-tpc/ch_benchmark.go @@ -44,10 +44,10 @@ func registerCHBenchmark(root *cobra.Command) { executeCH("prepare", nil) }, } - cmdPrepare.PersistentFlags().BoolVar(&chConfig.CreateTiFlashReplica, - "tiflash", - false, - "Create tiflash replica") + cmdPrepare.PersistentFlags().IntVar(&chConfig.TiFlashReplica, + "tiflash-replica", + 0, + "Number of tiflash replica") cmdPrepare.PersistentFlags().BoolVar(&chConfig.AnalyzeTable.Enable, "analyze", diff --git a/cmd/go-tpc/tpch.go b/cmd/go-tpc/tpch.go index d0f8501..f35a678 100644 --- a/cmd/go-tpc/tpch.go +++ b/cmd/go-tpc/tpch.go @@ -71,10 +71,10 @@ func registerTpch(root *cobra.Command) { }, } - cmdPrepare.PersistentFlags().BoolVar(&tpchConfig.CreateTiFlashReplica, - "tiflash", - false, - "Create tiflash replica") + cmdPrepare.PersistentFlags().IntVar(&tpchConfig.TiFlashReplica, + "tiflash-replica", + 0, + "Number of tiflash replica") cmdPrepare.PersistentFlags().BoolVar(&tpchConfig.AnalyzeTable.Enable, "analyze", diff --git a/tpch/ddl.go b/tpch/ddl.go index 22b1a12..af6f908 100644 --- a/tpch/ddl.go +++ b/tpch/ddl.go @@ -17,9 +17,9 @@ func (w *Workloader) createTableDDL(ctx context.Context, query string, tableName if _, err := s.Conn.ExecContext(ctx, query); err != nil { return err } - if w.cfg.CreateTiFlashReplica { + if w.cfg.TiFlashReplica != 0 { fmt.Printf("creating tiflash replica for %s\n", tableName) - replicaSQL := fmt.Sprintf("ALTER TABLE %s SET TIFLASH REPLICA 1", tableName) + replicaSQL := fmt.Sprintf("ALTER TABLE %s SET TIFLASH REPLICA %d", tableName, w.cfg.TiFlashReplica) if _, err := s.Conn.ExecContext(ctx, replicaSQL); err != nil { return err } diff --git a/tpch/workload.go b/tpch/workload.go index 69cfcbf..16f1386 100644 --- a/tpch/workload.go +++ b/tpch/workload.go @@ -31,16 +31,16 @@ type analyzeConfig struct { // Config is the configuration for tpch workload type Config struct { - Driver string - DBName string - RawQueries string - QueryNames []string - ScaleFactor int - EnableOutputCheck bool - CreateTiFlashReplica bool - AnalyzeTable analyzeConfig - ExecExplainAnalyze bool - PrepareThreads int + Driver string + DBName string + RawQueries string + QueryNames []string + ScaleFactor int + EnableOutputCheck bool + TiFlashReplica int + AnalyzeTable analyzeConfig + ExecExplainAnalyze bool + PrepareThreads int PlanReplayerConfig replayer.PlanReplayerConfig EnablePlanReplayer bool