diff --git a/pkg/loader/util.go b/pkg/loader/util.go index 8fae8cadc..b190ea1c4 100644 --- a/pkg/loader/util.go +++ b/pkg/loader/util.go @@ -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 ( @@ -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) @@ -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)) } diff --git a/tests/placement_rules/run.sh b/tests/placement_rules/run.sh index 9474956c8..3a3c6a10c 100644 --- a/tests/placement_rules/run.sh +++ b/tests/placement_rules/run.sh @@ -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'