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

loader: don't use ANSI_QUOTES for dumped data files #1497

Merged
merged 2 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion loader/convert_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func parseInsertStmt(sql []byte, table *tableInfo, columnMapping *cm.Mapping) ([
// INSERT INTO `t1` (`id`,`uid`,`name`,`info`) VALUES
// (1,10001,"Gabriel García Márquez",NULL),
// (2,10002,"Cien años de soledad",NULL);
// otherwise dumped SQL file has content like folloing:
// otherwise dumped SQL file has content like following:
// INSERT INTO `t1` VALUES
// (1,"hello"),
// (2,"world");
Expand Down
4 changes: 2 additions & 2 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ func (w *Worker) dispatchSQL(ctx context.Context, file string, offset int64, tab

lastOffset := cur

ansiquote := strings.Contains(w.cfg.SQLMode, "ANSI_QUOTES")
data := make([]byte, 0, 1024*1024)
br := bufio.NewReader(f)
for {
Expand Down Expand Up @@ -343,7 +342,8 @@ func (w *Worker) dispatchSQL(ctx context.Context, file string, offset int64, tab
return terror.Annotatef(err, "file %s", file)
}
} else if table.sourceTable != table.targetTable {
query = renameShardingTable(query, table.sourceTable, table.targetTable, ansiquote)
// dumped data files always use backquote as quotes
query = renameShardingTable(query, table.sourceTable, table.targetTable, false)
}

idx := strings.Index(query, "INSERT INTO")
Expand Down
20 changes: 1 addition & 19 deletions tests/safe_mode/conf/dm-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ is-sharding: true
meta-schema: "dm_meta"
enable-heartbeat: false
timezone: "Asia/Shanghai"
ignore-checking-items: ["auto_increment_ID"]

target-database:
host: "127.0.0.1"
Expand All @@ -16,15 +17,13 @@ mysql-instances:
- source-id: "mysql-replica-01"
block-allow-list: "instance"
route-rules: ["sharding-route-rules-table", "sharding-route-rules-schema"]
column-mapping-rules: ["instance-1"]
mydumper-config-name: "global"
loader-config-name: "global"
syncer-config-name: "global"

- source-id: "mysql-replica-02"
block-allow-list: "instance"
route-rules: ["sharding-route-rules-table", "sharding-route-rules-schema"]
column-mapping-rules: ["instance-2"]
mydumper-config-name: "global"
loader-config-name: "global"
syncer-config-name: "global"
Expand All @@ -47,23 +46,6 @@ routes:
schema-pattern: safe_mode_test
target-schema: safe_mode_target

column-mappings:
instance-1:
schema-pattern: "safe_mode_test"
table-pattern: "t*"
expression: "partition id"
source-column: "id"
target-column: "id"
arguments: ["1", "", "t"]

instance-2:
schema-pattern: "safe_mode_test"
table-pattern: "t*"
expression: "partition id"
source-column: "id"
target-column: "id"
arguments: ["2", "", "t"]

mydumpers:
global:
threads: 4
Expand Down
2 changes: 1 addition & 1 deletion tests/safe_mode/data/db1.prepare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ drop database if exists `safe_mode_test`;
create database `safe_mode_test`;
use `safe_mode_test`;
create table t1 (id bigint auto_increment, uid int, name varchar(80), primary key (`id`), unique key(`uid`)) DEFAULT CHARSET=utf8mb4;
create table t2 (id bigint auto_increment, uid int, name varchar(80), primary key (`id`), unique key(`uid`)) DEFAULT CHARSET=utf8mb4;
create table t2 (id bigint auto_increment, uid int, name varchar(80), primary key (`id`), unique key(`uid`)) DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 100;
insert into t1 (uid, name) values (10001, 'Gabriel García Márquez'), (10002, 'Cien años de soledad');
insert into t2 (uid, name) values (20001, 'José Arcadio Buendía'), (20002, 'Úrsula Iguarán'), (20003, 'José Arcadio');
4 changes: 2 additions & 2 deletions tests/safe_mode/data/db2.prepare.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
drop database if exists `safe_mode_test`;
create database `safe_mode_test`;
use `safe_mode_test`;
create table t2 (id bigint auto_increment, uid int, name varchar(80), primary key (`id`), unique key(`uid`)) DEFAULT CHARSET=utf8mb4;
create table t3 (id bigint auto_increment, uid int, name varchar(80), primary key (`id`), unique key(`uid`)) DEFAULT CHARSET=utf8mb4;
create table t2 (id bigint auto_increment, uid int, name varchar(80), primary key (`id`), unique key(`uid`)) DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 200;
create table t3 (id bigint auto_increment, uid int, name varchar(80), primary key (`id`), unique key(`uid`)) DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT = 300;
insert into t2 (uid, name) values (40000, 'Remedios Moscote'), (40001, 'Amaranta');
insert into t3 (uid, name) values (30001, 'Aureliano José'), (30002, 'Santa Sofía de la Piedad'), (30003, '17 Aurelianos');
2 changes: 2 additions & 0 deletions tests/safe_mode/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source $cur/../_utils/test_prepare
WORK_DIR=$TEST_DIR/$TEST_NAME

function consistency_none() {
run_sql_source2 "SET @@GLOBAL.SQL_MODE='ANSI_QUOTES'"
run_sql_file $cur/data/db1.prepare.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
check_contains 'Query OK, 2 rows affected'
run_sql_file $cur/data/db2.prepare.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
Expand Down Expand Up @@ -52,6 +53,7 @@ function consistency_none() {
gtid2=$(grep "GTID:" $WORK_DIR/worker2/dumped_data.test/metadata|tail -1|awk -F: '{print $2,":",$3}'|tr -d ' ')
check_log_contains $WORK_DIR/worker2/log/dm-worker.log "\[\"enable safe-mode because of inconsistent dump, will exit at\"\] \[task=test\] \[unit=\"binlog replication\"\] \[location=\"position: ($name2, $pos2), gtid-set: $gtid2\"\]"

run_sql_source2 "SET @@GLOBAL.SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'"
cleanup_data safe_mode_target
cleanup_process $*
}
Expand Down