Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

loader: fix bug that SQL Mode didn't take effect #1134

Merged
merged 4 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,23 @@ func (l *Loader) Init(ctx context.Context) (err error) {
dbCfg.RawDBCfg = config.DefaultRawDBConfig().
SetMaxIdleConns(l.cfg.PoolSize)

l.toDB, l.toDBConns, err = createConns(tctx, l.cfg, l.cfg.PoolSize)
// used to change loader's specified DB settings, currently SQL Mode
lcfg, err := l.cfg.Clone()
if err != nil {
return err
}
hasSQLMode := false
for k := range l.cfg.To.Session {
if strings.ToLower(k) == "sql_mode" {
hasSQLMode = true
break
}
}
if !hasSQLMode {
lcfg.To.Session["sql_mode"] = l.cfg.LoaderConfig.SQLMode
}

l.toDB, l.toDBConns, err = createConns(tctx, lcfg, l.cfg.PoolSize)
if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions tests/all_mode/conf/dm-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ meta-schema: "dm_meta"
heartbeat-update-interval: 1
heartbeat-report-interval: 1
timezone: "Asia/Shanghai"
ansi-quotes: false

target-database:
host: "127.0.0.1"
port: 4000
user: "root"
password: ""
session:
sql_mode: "NO_AUTO_VALUE_ON_ZERO,ANSI_QUOTES"
tidb_skip_utf8_check: 1
tidb_disable_txn_auto_retry: off
tidb_retry_limit: "10"
Expand Down
3 changes: 2 additions & 1 deletion tests/all_mode/data/db1.prepare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ drop database if exists `all_mode`;
create database `all_mode`;
use `all_mode`;
create table t1 (id int NOT NULL AUTO_INCREMENT, name varchar(20), PRIMARY KEY (id));
insert into t1 (id, name) values (1, 'arya'), (2, 'catelyn');
-- test ANSI_QUOTES works with quote in string
insert into t1 (id, name) values (1, 'ar"ya'), (2, 'catelyn');

-- test sql_mode=NO_AUTO_VALUE_ON_ZERO
insert into t1 (id, name) values (0, 'lalala');
Expand Down
9 changes: 1 addition & 8 deletions tests/all_mode/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,16 @@ function test_session_config(){
cp $cur/conf/dm-task.yaml $WORK_DIR/dm-task.yaml
sed -i "s/name: test/name: $ILLEGAL_CHAR_NAME/g" $WORK_DIR/dm-task.yaml

# enable ansi-quotes
sed -i 's/ansi-quotes: false/ansi-quotes: true/g' $WORK_DIR/dm-task.yaml
# error config
sed -i 's/tidb_retry_limit: "10"/tidb_retry_limit: "fjs"/g' $WORK_DIR/dm-task.yaml
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"start-task $WORK_DIR/dm-task.yaml --remove-meta" \
"Incorrect argument type to variable 'tidb_retry_limit'" 1

# sql_mode="ANSI_QUOTES"
sed -i 's/tidb_retry_limit: "fjs"/tidb_retry_limit: "10"/g' $WORK_DIR/dm-task.yaml
sed -i 's/sql_mode: ".*"/sql_mode: "ANSI_QUOTES"/g' $WORK_DIR/dm-task.yaml
dmctl_start_task "$WORK_DIR/dm-task.yaml" "--remove-meta"

# fail because insert 0 will auto generates the next serial number
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml 10 'fail'
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"stop-task $ILLEGAL_CHAR_NAME"\
"\"result\": true" 3
Expand Down Expand Up @@ -85,8 +80,6 @@ function run() {
# start DM task only
cp $cur/conf/dm-task.yaml $WORK_DIR/dm-task.yaml
sed -i "s/name: test/name: $ILLEGAL_CHAR_NAME/g" $WORK_DIR/dm-task.yaml
# test deprecated config
sed -i 's/enable-ansi-quotes: false/enable-ansi-quotes: true/g' $WORK_DIR/dm-task.yaml
dmctl_start_task "$WORK_DIR/dm-task.yaml" "--remove-meta"

# use sync_diff_inspector to check full dump loader
Expand Down