Skip to content

Commit

Permalink
lightning: fix routes panic for csv data load (#45405)
Browse files Browse the repository at this point in the history
close #43284
  • Loading branch information
lyzx2001 authored Jul 24, 2023
1 parent e68c8ff commit d9f771f
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 1 deletion.
18 changes: 18 additions & 0 deletions br/pkg/lightning/mydump/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}

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'
2 changes: 1 addition & 1 deletion br/tests/run_group.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down

0 comments on commit d9f771f

Please sign in to comment.