Skip to content

Commit

Permalink
lightning: fix routes panic for csv data load (#45405) (#45537)
Browse files Browse the repository at this point in the history
close #43284
  • Loading branch information
ti-chi-bot committed Aug 7, 2023
1 parent 032726c commit df7760f
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 0 deletions.
18 changes: 18 additions & 0 deletions br/pkg/lightning/mydump/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,30 @@ func (s *mdLoaderSetup) route() error {
}
}
for _, info := range s.tableSchemas {
if _, ok := knownDBNames[info.TableName.Schema]; !ok {
knownDBNames[info.TableName.Schema] = &dbInfo{
fileMeta: info.FileMeta,
count: 1,
}
}
knownDBNames[info.TableName.Schema].count++
}
for _, info := range s.viewSchemas {
if _, ok := knownDBNames[info.TableName.Schema]; !ok {
knownDBNames[info.TableName.Schema] = &dbInfo{
fileMeta: info.FileMeta,
count: 1,
}
}
knownDBNames[info.TableName.Schema].count++
}
for _, info := range s.tableDatas {
if _, ok := knownDBNames[info.TableName.Schema]; !ok {
knownDBNames[info.TableName.Schema] = &dbInfo{
fileMeta: info.FileMeta,
count: 1,
}
}
knownDBNames[info.TableName.Schema].count++
}

Expand Down
17 changes: 17 additions & 0 deletions br/pkg/lightning/mydump/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,23 @@ func TestRouter(t *testing.T) {
}
}

func TestRoutesPanic(t *testing.T) {
s := newTestMydumpLoaderSuite(t)
s.cfg.Routes = []*router.TableRule{
{
SchemaPattern: "test1",
TargetSchema: "test",
},
}

s.touch(t, "test1.dump_test.001.sql")
s.touch(t, "test1.dump_test.002.sql")
s.touch(t, "test1.dump_test.003.sql")

_, err := md.NewMyDumpLoader(context.Background(), s.cfg)
require.NoError(t, err)
}

func TestBadRouterRule(t *testing.T) {
s := newTestMydumpLoaderSuite(t)

Expand Down
9 changes: 9 additions & 0 deletions br/tests/lightning_routes_panic/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tikv-importer]
backend = 'local'

# here we're verifying that routes does not panic for csv data load.
[[routes]]
schema-pattern = "test1"
table-pattern = "d*"
target-schema = "test"
target-table = "u"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into dump_test values (1.0);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into dump_test values (6.0);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into dump_test values (36.0);
18 changes: 18 additions & 0 deletions br/tests/lightning_routes_panic/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

# Basic check for whether routing rules work

set -eux

run_sql 'DROP DATABASE IF EXISTS test1;'
run_sql 'DROP DATABASE IF EXISTS test;'

run_sql 'CREATE DATABASE test1;'
run_sql 'CREATE DATABASE test;'
run_sql 'CREATE TABLE test1.dump_test (x real primary key);'
run_sql 'CREATE TABLE test.u (x real primary key);'

run_lightning

run_sql 'SELECT sum(x) FROM test.u;'
check_contains 'sum(x): 43'

0 comments on commit df7760f

Please sign in to comment.