Skip to content

Commit fe7bcf1

Browse files
authored
lightning: fix routes panic for csv data load (pingcap#45405) (pingcap#45534)
close pingcap#43284
1 parent 4b8ac1a commit fe7bcf1

File tree

7 files changed

+65
-0
lines changed

7 files changed

+65
-0
lines changed

br/pkg/lightning/mydump/loader.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,30 @@ func (s *mdLoaderSetup) route() error {
368368
}
369369
}
370370
for _, info := range s.tableSchemas {
371+
if _, ok := knownDBNames[info.TableName.Schema]; !ok {
372+
knownDBNames[info.TableName.Schema] = &dbInfo{
373+
fileMeta: info.FileMeta,
374+
count: 1,
375+
}
376+
}
371377
knownDBNames[info.TableName.Schema].count++
372378
}
373379
for _, info := range s.viewSchemas {
380+
if _, ok := knownDBNames[info.TableName.Schema]; !ok {
381+
knownDBNames[info.TableName.Schema] = &dbInfo{
382+
fileMeta: info.FileMeta,
383+
count: 1,
384+
}
385+
}
374386
knownDBNames[info.TableName.Schema].count++
375387
}
376388
for _, info := range s.tableDatas {
389+
if _, ok := knownDBNames[info.TableName.Schema]; !ok {
390+
knownDBNames[info.TableName.Schema] = &dbInfo{
391+
fileMeta: info.FileMeta,
392+
count: 1,
393+
}
394+
}
377395
knownDBNames[info.TableName.Schema].count++
378396
}
379397

br/pkg/lightning/mydump/loader_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,23 @@ func TestRouter(t *testing.T) {
659659
}
660660
}
661661

662+
func TestRoutesPanic(t *testing.T) {
663+
s := newTestMydumpLoaderSuite(t)
664+
s.cfg.Routes = []*router.TableRule{
665+
{
666+
SchemaPattern: "test1",
667+
TargetSchema: "test",
668+
},
669+
}
670+
671+
s.touch(t, "test1.dump_test.001.sql")
672+
s.touch(t, "test1.dump_test.002.sql")
673+
s.touch(t, "test1.dump_test.003.sql")
674+
675+
_, err := md.NewMyDumpLoader(context.Background(), s.cfg)
676+
require.NoError(t, err)
677+
}
678+
662679
func TestBadRouterRule(t *testing.T) {
663680
s := newTestMydumpLoaderSuite(t)
664681

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tikv-importer]
2+
backend = 'local'
3+
4+
# here we're verifying that routes does not panic for csv data load.
5+
[[routes]]
6+
schema-pattern = "test1"
7+
table-pattern = "d*"
8+
target-schema = "test"
9+
target-table = "u"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
insert into dump_test values (1.0);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
insert into dump_test values (6.0);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
insert into dump_test values (36.0);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
# Basic check for whether routing rules work
4+
5+
set -eux
6+
7+
run_sql 'DROP DATABASE IF EXISTS test1;'
8+
run_sql 'DROP DATABASE IF EXISTS test;'
9+
10+
run_sql 'CREATE DATABASE test1;'
11+
run_sql 'CREATE DATABASE test;'
12+
run_sql 'CREATE TABLE test1.dump_test (x real primary key);'
13+
run_sql 'CREATE TABLE test.u (x real primary key);'
14+
15+
run_lightning
16+
17+
run_sql 'SELECT sum(x) FROM test.u;'
18+
check_contains 'sum(x): 43'

0 commit comments

Comments
 (0)