From 26d27e2ab871c6f9f0217f76e0ae3d471b52fa22 Mon Sep 17 00:00:00 2001 From: RidRisR <79858083+RidRisR@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:19:15 +0100 Subject: [PATCH 1/5] fixed --- br/pkg/task/restore.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/br/pkg/task/restore.go b/br/pkg/task/restore.go index f53b7b72a9121..7aa5303e9c6e2 100644 --- a/br/pkg/task/restore.go +++ b/br/pkg/task/restore.go @@ -1323,10 +1323,6 @@ func Exhaust(ec <-chan error) []error { } func checkTableExistence(ctx context.Context, mgr *conn.Mgr, tables []*metautil.Table, g glue.Glue) error { - // Tasks from br clp client use other checks to validate - if g.GetClient() != glue.ClientSql { - return nil - } message := "table already exists: " allUnique := true for _, table := range tables { From 85a201488ae3e0c9e50cd3a9a562c5c14e05b221 Mon Sep 17 00:00:00 2001 From: RidRisR <79858083+RidRisR@users.noreply.github.com> Date: Fri, 13 Dec 2024 03:34:48 +0100 Subject: [PATCH 2/5] add test case --- br/tests/br_check_dup_table/run.sh | 64 ++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 br/tests/br_check_dup_table/run.sh diff --git a/br/tests/br_check_dup_table/run.sh b/br/tests/br_check_dup_table/run.sh new file mode 100644 index 0000000000000..1523cd1c2a03b --- /dev/null +++ b/br/tests/br_check_dup_table/run.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# +# Copyright 2019 PingCAP, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eu +DB="$TEST_NAME" + +run_sql "CREATE DATABASE $DB;" + +run_sql "CREATE TABLE $DB.usertable1 ( \ + YCSB_KEY varchar(64) NOT NULL, \ + FIELD0 varchar(1) DEFAULT NULL, \ + PRIMARY KEY (YCSB_KEY) \ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;" + +run_sql "INSERT INTO $DB.usertable1 VALUES (\"a\", \"b\");" +run_sql "INSERT INTO $DB.usertable1 VALUES (\"aa\", \"b\");" + +run_sql "CREATE TABLE $DB.usertable2 ( \ + YCSB_KEY varchar(64) NOT NULL, \ + FIELD0 varchar(1) DEFAULT NULL, \ + PRIMARY KEY (YCSB_KEY) \ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;" + +run_sql "INSERT INTO $DB.usertable2 VALUES (\"c\", \"d\");" +# backup db +echo "backup start..." +run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB" + +run_sql "DROP DATABASE $DB;" + +# restore db +echo "restore start..." +run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR + +table_count=$(run_sql "use $DB; show tables;" | grep "Tables_in" | wc -l) +if [ "$table_count" -ne "2" ];then + echo "TEST: [$TEST_NAME] failed!" + exit 1 +fi + +# restore db again +echo "restore start..." +LOG_OUTPUT=$(run_br restore db --db "$DB" -s "local://$TEST_DIR/$DB" --pd "$PD_ADDR" 2>&1) + +# Check if the log contains 'ErrTableAlreadyExisted' +if ! echo "$LOG_OUTPUT" | grep -q "ErrTableAlreadyExisted"; then + echo "Error: 'ErrTableAlreadyExisted' not found in logs." + echo "Log output:" + echo "$LOG_OUTPUT" + exit 1 +fi \ No newline at end of file From cdebcbc713932e96669dda553e6576601acb7a24 Mon Sep 17 00:00:00 2001 From: RidRisR <79858083+RidRisR@users.noreply.github.com> Date: Fri, 13 Dec 2024 04:13:33 +0100 Subject: [PATCH 3/5] fix test --- br/tests/br_check_dup_table/run.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/br/tests/br_check_dup_table/run.sh b/br/tests/br_check_dup_table/run.sh index 1523cd1c2a03b..2337a031143cd 100644 --- a/br/tests/br_check_dup_table/run.sh +++ b/br/tests/br_check_dup_table/run.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright 2019 PingCAP, Inc. +# Copyright 2024 PingCAP, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -53,12 +53,16 @@ fi # restore db again echo "restore start..." -LOG_OUTPUT=$(run_br restore db --db "$DB" -s "local://$TEST_DIR/$DB" --pd "$PD_ADDR" 2>&1) +LOG_OUTPUT=$(run_br restore db --db "$DB" -s "local://$TEST_DIR/$DB" --pd "$PD_ADDR" 2>&1 || true) # Check if the log contains 'ErrTableAlreadyExisted' -if ! echo "$LOG_OUTPUT" | grep -q "ErrTableAlreadyExisted"; then +if ! echo "$LOG_OUTPUT" | grep -q "BR:Restore:ErrTablesAlreadyExisted"; then echo "Error: 'ErrTableAlreadyExisted' not found in logs." echo "Log output:" echo "$LOG_OUTPUT" exit 1 -fi \ No newline at end of file +else + echo "restore failed as expect" +fi + +run_sql "DROP DATABASE $DB;" \ No newline at end of file From ef19fc7b18b5573e7ff34f568c190fd290352c29 Mon Sep 17 00:00:00 2001 From: RidRisR <79858083+RidRisR@users.noreply.github.com> Date: Fri, 13 Dec 2024 04:30:27 +0100 Subject: [PATCH 4/5] add new test into groups --- br/tests/run_group_br_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/br/tests/run_group_br_tests.sh b/br/tests/run_group_br_tests.sh index fdb9dd6d6ea6b..0c9518f69fb97 100755 --- a/br/tests/run_group_br_tests.sh +++ b/br/tests/run_group_br_tests.sh @@ -21,10 +21,10 @@ mkdir -p $COV_DIR declare -A groups groups=( ["G00"]="br_300_small_tables br_backup_empty br_backup_version br_cache_table br_case_sensitive br_charset_gbk br_check_new_collocation_enable br_history br_gcs br_rawkv br_tidb_placement_policy" - ["G01"]="br_autoid br_crypter2 br_db br_db_online br_db_online_newkv br_db_skip br_debug_meta br_ebs br_foreign_key br_full br_table_partition br_full_ddl br_tiflash" + ["G01"]="br_autoid br_crypter2 br_db br_check_dup_table br_db_online br_db_online_newkv br_db_skip br_debug_meta br_ebs br_foreign_key br_full br_table_partition br_full_ddl br_tiflash" ["G02"]="br_full_cluster_restore br_full_index br_incremental_ddl br_pitr_failpoint br_pitr_gc_safepoint br_other br_pitr_long_running_schema_loading" ["G03"]='br_incompatible_tidb_config br_incremental br_incremental_index br_incremental_only_ddl br_incremental_same_table br_insert_after_restore br_key_locked br_log_test br_move_backup br_mv_index' - ["G04"]='br_range br_replica_read br_restore_TDE_enable br_restore_log_task_enable br_s3 br_shuffle_leader br_shuffle_region br_single_table' + ["G04"]='br_range br_replica_read br_restore_TDE_enable br_restore_log_task_enable br_s3 br_shuffle_leader br_shuffle_region br_single_table ' ["G05"]='br_skip_checksum br_split_region_fail br_systables br_table_filter br_txn br_stats br_clustered_index br_crypter br_partition_add_index' ["G06"]='br_tikv_outage br_tikv_outage3 br_restore_checkpoint br_encryption' ["G07"]='br_pitr' From 065fdeef50938b7b3dfdefa2547f0587ebd5806f Mon Sep 17 00:00:00 2001 From: RidRisR <79858083+RidRisR@users.noreply.github.com> Date: Fri, 13 Dec 2024 06:21:09 +0100 Subject: [PATCH 5/5] fix legacy tests --- br/tests/br_300_small_tables/run.sh | 10 +++++----- br/tests/br_incompatible_tidb_config/run.sh | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/br/tests/br_300_small_tables/run.sh b/br/tests/br_300_small_tables/run.sh index bff3f80327df6..e83558b439902 100644 --- a/br/tests/br_300_small_tables/run.sh +++ b/br/tests/br_300_small_tables/run.sh @@ -73,16 +73,15 @@ else fi # truncate every table -# (FIXME: drop instead of truncate. if we drop then create-table will still be executed and wastes time executing DDLs) i=1 while [ $i -le $TABLES_COUNT ]; do - run_sql "truncate $DB.sbtest$i;" + run_sql "drop table $DB.sbtest$i;" i=$(($i+1)) done rm -rf $RESTORE_LOG echo "restore 1/300 of the table start..." -run_br restore table --db $DB --table "sbtest100" --log-file $RESTORE_LOG -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --no-schema +run_br restore table --db $DB --table "sbtest100" --log-file $RESTORE_LOG -s "local://$TEST_DIR/$DB" --pd $PD_ADDR restore_size=`grep "restore-data-size" "${RESTORE_LOG}" | grep -oP '\[\K[^\]]+' | grep "restore-data-size" | awk -F '=' '{print $2}' | grep -oP '\d*\.?\d+'` echo "restore data size is ${restore_size}" @@ -98,9 +97,10 @@ else exit 1 fi +run_sql "drop table $DB.sbtest100;" + # restore db -# (FIXME: shouldn't need --no-schema to be fast, currently the alter-auto-id DDL slows things down) echo "restore start..." -run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --no-schema +run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR run_sql "DROP DATABASE $DB;" diff --git a/br/tests/br_incompatible_tidb_config/run.sh b/br/tests/br_incompatible_tidb_config/run.sh index 973e54da74537..d4f73dfa7ee56 100755 --- a/br/tests/br_incompatible_tidb_config/run.sh +++ b/br/tests/br_incompatible_tidb_config/run.sh @@ -54,14 +54,14 @@ run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_ run_sql "drop schema $DB;" # restore with ddl(create table) job one by one run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" --ddl-batch-size=1 - +run_sql "drop schema $DB;" run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_TABLE" --ddl-batch-size=1 # restore run_sql "drop schema $DB;" # restore with batch create table run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" --ddl-batch-size=128 - +run_sql "drop schema $DB;" run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_TABLE" --ddl-batch-size=128 run_sql "drop schema $DB;"