Skip to content

Commit

Permalink
drainer: Ignore all tidb placement operations (#1141)
Browse files Browse the repository at this point in the history
close #1140
  • Loading branch information
lcwangchao authored Mar 11, 2022
1 parent 0f865d8 commit 2b86683
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions pkg/loader/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ import (

var (
// ErrTableNotExist means the table not exist.
ErrTableNotExist = errors.New("table not exist")
defaultTiDBTxnMode = "optimistic"
ErrTableNotExist = errors.New("table not exist")
defaultTiDBTxnMode = "optimistic"
defaultTiDBPlacementMode = "ignore"
)

const (
Expand Down Expand Up @@ -133,6 +134,8 @@ func createDBWitSessions(dsn string, params map[string]string) (db *gosql.DB, er
// default is false, must enable for insert value explicit, or can't replicate.
"allow_auto_random_explicit_insert": "1",
"tidb_txn_mode": defaultTiDBTxnMode,
// ignore all placement settings
"tidb_placement_mode": defaultTiDBPlacementMode,
}
var tryDB *gosql.DB
tryDB, err = gosql.Open("mysql", dsn)
Expand Down Expand Up @@ -164,6 +167,9 @@ func createDBWitSessions(dsn string, params map[string]string) (db *gosql.DB, er
}

for k, v := range support {
// The value should be quoted and then query escaped
// see: https://github.com/go-sql-driver/mysql#system-variables
v = fmt.Sprintf("'%s'", v)
dsn += fmt.Sprintf("&%s=%s", k, url.QueryEscape(v))
}

Expand Down
4 changes: 3 additions & 1 deletion tests/placement_rules/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ run_sql 'CREATE PLACEMENT POLICY x1 FOLLOWERS=4'
run_sql 'CREATE TABLE placement_test.t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(100)) PLACEMENT POLICY=x1;'
run_sql "INSERT INTO placement_test.t1 (a,b) VALUES(1,'a'),(2,'b'),(3,'c'),(4,'d');"
run_sql "INSERT INTO placement_test.t1 (a,b) VALUES(5,'e'),(6,'f'),(7,'g'),(8,'h');"
down_run_sql 'CREATE PLACEMENT POLICY x1 FOLLOWERS=4'

sleep 3

down_run_sql 'SHOW PLACEMENT'
check_not_contains 'Target: POLICY x1'
check_not_contains 'Target: TABLE placement_test.t1'
down_run_sql 'SELECT a, b FROM placement_test.t1 order by a'
check_contains 'a: 7'
check_contains 'b: g'
Expand Down

0 comments on commit 2b86683

Please sign in to comment.