Skip to content

Commit

Permalink
Add test for DDL "set tiflash mode" (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongyunyan authored Jul 8, 2022
1 parent e31eb18 commit fa2543d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/pingcap/log v1.1.0
github.com/pingcap/tidb v1.1.0-beta.0.20220706110502-6531bd1ff928
github.com/pingcap/tidb-tools v6.1.0+incompatible
github.com/pingcap/tidb/parser v0.0.0-20220706054102-55aea2787d0f
github.com/pingcap/tidb/parser v0.0.0-20220707071503-6e22e47f06ab
github.com/pingcap/tipb v0.0.0-20220706024432-7be3cc83a7d5
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/client_model v0.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ github.com/pingcap/tidb v1.1.0-beta.0.20220706110502-6531bd1ff928 h1:KfMpywlFh8E
github.com/pingcap/tidb v1.1.0-beta.0.20220706110502-6531bd1ff928/go.mod h1:IIqGhAIt0r50T65i+1Mc0DZQFxgmwaaUq7UitomEfwA=
github.com/pingcap/tidb-tools v6.1.0+incompatible h1:vq781SRL0iv92/rQYbCxjaXOa+EnMifDu0hN5/5N3bo=
github.com/pingcap/tidb-tools v6.1.0+incompatible/go.mod h1:XGdcy9+yqlDSEMTpOXnwf3hiTeqrV6MN/u1se9N8yIM=
github.com/pingcap/tidb/parser v0.0.0-20220706054102-55aea2787d0f h1:QTR0OiutuhdTXGyoWVU8aNMsNJ6ntYC8ebrlP7dXqEk=
github.com/pingcap/tidb/parser v0.0.0-20220706054102-55aea2787d0f/go.mod h1:wjvp+T3/T9XYt0nKqGX3Kc1AKuyUcfno6LTc6b2A6ew=
github.com/pingcap/tidb/parser v0.0.0-20220707071503-6e22e47f06ab h1:Q0h+KW72ixb4DH66byWKOiL0SVvNSci8Phs+SlqJiPE=
github.com/pingcap/tidb/parser v0.0.0-20220707071503-6e22e47f06ab/go.mod h1:wjvp+T3/T9XYt0nKqGX3Kc1AKuyUcfno6LTc6b2A6ew=
github.com/pingcap/tipb v0.0.0-20220706024432-7be3cc83a7d5 h1:XaTE4ZhQbQtQZtAVzlZh/Pf6SjFfMSTe1ia2nGcl36Y=
github.com/pingcap/tipb v0.0.0-20220706024432-7be3cc83a7d5/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
Expand Down
13 changes: 9 additions & 4 deletions pkg/loader/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func (s *loaderImpl) processMysqlDDL(ddl *DDL) error {
return nil
})

if err != nil && isSetTiFlashReplica(ddl.SQL) {
if err != nil && isTiFlashDDL(ddl.SQL) {
return nil
}

Expand Down Expand Up @@ -984,13 +984,18 @@ func getOracleAppliedTS(db *gosql.DB) int64 {
return appliedTS
}

func isSetTiFlashReplica(sql string) bool {
func isTiFlashDDL(sql string) bool {
// We need to ignore all errors related with TiFlash,
// Since TiFlash statements are not available in other dbs.
// TiFlash related DDL:
// alter table xx set tiflash replica xx
// alter table xx set tiflash mode xx

stmt, err := parser.New().ParseOneStmt(sql, "", "")
if err != nil {
log.Error("failed to parse", zap.Error(err), zap.String("sql", sql))
return false
}

n, ok := stmt.(*ast.AlterTableStmt)
if !ok {
return false
Expand All @@ -1001,7 +1006,7 @@ func isSetTiFlashReplica(sql string) bool {
}

for _, spec := range n.Specs {
if spec.Tp == ast.AlterTableSetTiFlashReplica {
if spec.Tp == ast.AlterTableSetTiFlashReplica || spec.Tp == ast.AlterTableSetTiFlashMode {
return true
}
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/loader/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@ func (cs *LoadSuite) TearDownTest(c *check.C) {

func (cs *LoadSuite) TestTiFlash(c *check.C) {
sql := "ALTER TABLE t SET TIFLASH REPLICA 3 LOCATION LABELS \"rack\", \"host\", \"abc\""
res := isSetTiFlashReplica(sql)
res := isTiFlashDDL(sql)
c.Assert(res, check.IsTrue)

sql = "ALTER TABLE t SET TIFLASH MODE FAST"
res = isTiFlashDDL(sql)
c.Assert(res, check.IsTrue)

sql = "ALTER TABLE t SET TIFLASH MODE NORMAL"
res = isTiFlashDDL(sql)
c.Assert(res, check.IsTrue)

sql = "create table a(id int)"
res = isSetTiFlashReplica(sql)
res = isTiFlashDDL(sql)
c.Assert(res, check.IsFalse)
}

Expand Down

0 comments on commit fa2543d

Please sign in to comment.