diff --git a/br/pkg/lightning/mydump/loader.go b/br/pkg/lightning/mydump/loader.go index fe733d043b6c6..f57d2d0db7761 100644 --- a/br/pkg/lightning/mydump/loader.go +++ b/br/pkg/lightning/mydump/loader.go @@ -517,12 +517,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++ } diff --git a/br/pkg/lightning/mydump/loader_test.go b/br/pkg/lightning/mydump/loader_test.go index 58236d7b626f5..30928ac06e1d1 100644 --- a/br/pkg/lightning/mydump/loader_test.go +++ b/br/pkg/lightning/mydump/loader_test.go @@ -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) diff --git a/br/tests/lightning_routes_panic/config.toml b/br/tests/lightning_routes_panic/config.toml new file mode 100644 index 0000000000000..1e6e444e7fe74 --- /dev/null +++ b/br/tests/lightning_routes_panic/config.toml @@ -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" diff --git a/br/tests/lightning_routes_panic/data/test1.dump_test.001.sql b/br/tests/lightning_routes_panic/data/test1.dump_test.001.sql new file mode 100644 index 0000000000000..22f20b3808dd1 --- /dev/null +++ b/br/tests/lightning_routes_panic/data/test1.dump_test.001.sql @@ -0,0 +1 @@ +insert into dump_test values (1.0); diff --git a/br/tests/lightning_routes_panic/data/test1.dump_test.002.sql b/br/tests/lightning_routes_panic/data/test1.dump_test.002.sql new file mode 100644 index 0000000000000..e1bfd3fd8f7c1 --- /dev/null +++ b/br/tests/lightning_routes_panic/data/test1.dump_test.002.sql @@ -0,0 +1 @@ +insert into dump_test values (6.0); diff --git a/br/tests/lightning_routes_panic/data/test1.dump_test.003.sql b/br/tests/lightning_routes_panic/data/test1.dump_test.003.sql new file mode 100644 index 0000000000000..403e49b03fbf4 --- /dev/null +++ b/br/tests/lightning_routes_panic/data/test1.dump_test.003.sql @@ -0,0 +1 @@ +insert into dump_test values (36.0); diff --git a/br/tests/lightning_routes_panic/run.sh b/br/tests/lightning_routes_panic/run.sh new file mode 100755 index 0000000000000..37661999b3320 --- /dev/null +++ b/br/tests/lightning_routes_panic/run.sh @@ -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' diff --git a/br/tests/run_group.sh b/br/tests/run_group.sh index 589ed710ec623..41348316fc12e 100755 --- a/br/tests/run_group.sh +++ b/br/tests/run_group.sh @@ -33,7 +33,7 @@ groups=( ["G12"]='lightning_drop_other_tables_halfway lightning_duplicate_detection lightning_duplicate_detection_new lightning_duplicate_resolution lightning_duplicate_resolution_incremental lightning_error_summary lightning_examples lightning_exotic_filenames lightning_extend_routes lightning_fail_fast' ["G13"]='lightning_fail_fast_on_nonretry_err lightning_file_routing lightning_foreign_key lightning_gcs lightning_generated_columns lightning_ignore_columns lightning_import_compress lightning_incremental lightning_issue_282' ["G14"]='lightning_issue_40657 lightning_issue_410 lightning_issue_519 lightning_local_backend lightning_max_incr lightning_max_random lightning_multi_valued_index lightning_new_collation lightning_no_schema' - ["G15"]='lightning_parquet lightning_partition_incremental lightning_partitioned-table lightning_record_network lightning_reload_cert lightning_restore lightning_routes lightning_row-format-v2 lightning_s3' + ["G15"]='lightning_parquet lightning_partition_incremental lightning_partitioned-table lightning_record_network lightning_reload_cert lightning_restore lightning_routes lightning_routes_panic lightning_row-format-v2 lightning_s3' ["G16"]='lightning_shard_rowid lightning_source_linkfile lightning_sqlmode lightning_tidb_duplicate_data lightning_tidb_rowid lightning_tiflash lightning_tikv_multi_rocksdb lightning_too_many_columns lightning_tool_135' ["G17"]='lightning_tool_1420 lightning_tool_1472 lightning_tool_241 lightning_ttl lightning_unused_config_keys lightning_various_types lightning_view lightning_write_batch lightning_write_limit' )