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

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lance6716 committed Dec 1, 2020
1 parent 0b14140 commit d168716
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
14 changes: 3 additions & 11 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1340,19 +1340,9 @@ func (l *Loader) restoreData(ctx context.Context) error {
}

dispatchMap := make(map[string]*fileJob)

// restore db in sort
dbs := make([]string, 0, len(l.db2Tables))
for db := range l.db2Tables {
dbs = append(dbs, db)
}

tctx := tcontext.NewContext(ctx, l.logger)

for _, db := range dbs {
tables := l.db2Tables[db]
views := l.db2Views[db]

for db, tables := range l.db2Tables {
// create db
dbFile := fmt.Sprintf("%s/%s-schema-create.sql", l.cfg.Dir, db)
l.logger.Info("start to create schema", zap.String("schema file", dbFile))
Expand Down Expand Up @@ -1420,7 +1410,9 @@ func (l *Loader) restoreData(ctx context.Context) error {
dispatchMap[fmt.Sprintf("%s_%s_%s", db, table, file)] = j
}
}
}

for db, views := range l.db2Views {
for view := range views {
viewFile := fmt.Sprintf("%s/%s.%s-schema-view.sql", l.cfg.Dir, db, view)
l.logger.Info("start to create view", zap.String("view file", viewFile))
Expand Down
24 changes: 22 additions & 2 deletions tests/sharding/conf/dm-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ target-database:
mysql-instances:
- source-id: "mysql-replica-01"
block-allow-list: "instance"
route-rules: ["sharding-route-rules-table", "sharding-route-rules-schema"]
route-rules: ["sharding-route-rules-table", "sharding-route-rules-schema", "shardview-route-table", "shardview-route-view", "shardview-route-schema"]
column-mapping-rules: ["instance-1"]
mydumper-config-name: "global"
loader-config-name: "global"
Expand All @@ -31,12 +31,16 @@ mysql-instances:

block-allow-list:
instance:
do-dbs: ["~^sharding[\\d]+"]
do-dbs: ["~^sharding[\\d]+", "~^shardview[\\d]+"]
do-tables:
- db-name: "~^sharding[\\d]+"
tbl-name: "~^t[\\d]+"
- db-name: "~^sharding[\\d]+"
tbl-name: "~^v[\\d]+"
- db-name: "~^shardview[\\d]+"
tbl-name: "~^t[\\d]+"
- db-name: "~^shardview[\\d]+"
tbl-name: "~^v[\\d]+"

routes:
sharding-route-rules-table:
Expand All @@ -49,6 +53,22 @@ routes:
schema-pattern: sharding*
target-schema: db_target

shardview-route-table:
schema-pattern: shardview*
table-pattern: t*
target-schema: dbview_target
target-table: t_target

shardview-route-view:
schema-pattern: shardview*
table-pattern: v*
target-schema: dbview_target
target-table: v_target

shardview-route-schema:
schema-pattern: shardview*
target-schema: dbview_target

column-mappings:
instance-1:
schema-pattern: "sharding*"
Expand Down
8 changes: 8 additions & 0 deletions tests/sharding/data/db1.prepare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ create table t2 (id bigint auto_increment, uid int, name varchar(80), info varch
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');
create view v1 as select id from t1;

create database `shardview1`;
create database `shardview2`;
create table shardview1.t1 (id int primary key);
create table shardview2.t1 (id int primary key);
create view shardview1.v1 as select id from shardview2.t1;
create view shardview2.v1 as select id from shardview1.t1;
-- after sharding route merge, there should be a view reference merged table
2 changes: 2 additions & 0 deletions tests/sharding/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function run() {

run_sql_tidb "show create view db_target.v1"
check_contains "View: v1"
run_sql_tidb "show create view dbview_target.v_target"
check_contains "View: v_target"

run_sql_file $cur/data/db1.increment.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1
run_sql_file $cur/data/db2.increment.sql $MYSQL_HOST2 $MYSQL_PORT2 $MYSQL_PASSWORD2
Expand Down

0 comments on commit d168716

Please sign in to comment.