Skip to content

Commit

Permalink
support add multiple tiflash replica (#148)
Browse files Browse the repository at this point in the history
* support add multiple tiflash replica

Signed-off-by: Lloyd-Pottiger <[email protected]>

* fix typo in README

Signed-off-by: Lloyd-Pottiger <[email protected]>

* address comments

Signed-off-by: Lloyd-Pottiger <[email protected]>

Signed-off-by: Lloyd-Pottiger <[email protected]>
Co-authored-by: dbsid <[email protected]>
  • Loading branch information
Lloyd-Pottiger and dbsid authored Oct 10, 2022
1 parent 87d0876 commit 5199ebb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
22 changes: 11 additions & 11 deletions ch/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/go-tpc/ch_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions cmd/go-tpc/tpch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tpch/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 10 additions & 10 deletions tpch/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5199ebb

Please sign in to comment.