Skip to content

Commit a4f58fe

Browse files
authored
br: make table existence check unified on different br client (#58211) (#58262)
close #58168
1 parent 87ed1fe commit a4f58fe

File tree

5 files changed

+77
-13
lines changed

5 files changed

+77
-13
lines changed

br/pkg/task/restore.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,10 +1323,6 @@ func Exhaust(ec <-chan error) []error {
13231323
}
13241324

13251325
func checkTableExistence(ctx context.Context, mgr *conn.Mgr, tables []*metautil.Table, g glue.Glue) error {
1326-
// Tasks from br clp client use other checks to validate
1327-
if g.GetClient() != glue.ClientSql {
1328-
return nil
1329-
}
13301326
message := "table already exists: "
13311327
allUnique := true
13321328
for _, table := range tables {

br/tests/br_300_small_tables/run.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,15 @@ else
7373
fi
7474

7575
# truncate every table
76-
# (FIXME: drop instead of truncate. if we drop then create-table will still be executed and wastes time executing DDLs)
7776
i=1
7877
while [ $i -le $TABLES_COUNT ]; do
79-
run_sql "truncate $DB.sbtest$i;"
78+
run_sql "drop table $DB.sbtest$i;"
8079
i=$(($i+1))
8180
done
8281

8382
rm -rf $RESTORE_LOG
8483
echo "restore 1/300 of the table start..."
85-
run_br restore table --db $DB --table "sbtest100" --log-file $RESTORE_LOG -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --no-schema
84+
run_br restore table --db $DB --table "sbtest100" --log-file $RESTORE_LOG -s "local://$TEST_DIR/$DB" --pd $PD_ADDR
8685
restore_size=`grep "restore-data-size" "${RESTORE_LOG}" | grep -oP '\[\K[^\]]+' | grep "restore-data-size" | awk -F '=' '{print $2}' | grep -oP '\d*\.?\d+'`
8786
echo "restore data size is ${restore_size}"
8887

@@ -98,9 +97,10 @@ else
9897
exit 1
9998
fi
10099

100+
run_sql "drop table $DB.sbtest100;"
101+
101102
# restore db
102-
# (FIXME: shouldn't need --no-schema to be fast, currently the alter-auto-id DDL slows things down)
103103
echo "restore start..."
104-
run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --no-schema
104+
run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR
105105

106106
run_sql "DROP DATABASE $DB;"

br/tests/br_check_dup_table/run.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/sh
2+
#
3+
# Copyright 2024 PingCAP, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -eu
18+
DB="$TEST_NAME"
19+
20+
run_sql "CREATE DATABASE $DB;"
21+
22+
run_sql "CREATE TABLE $DB.usertable1 ( \
23+
YCSB_KEY varchar(64) NOT NULL, \
24+
FIELD0 varchar(1) DEFAULT NULL, \
25+
PRIMARY KEY (YCSB_KEY) \
26+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"
27+
28+
run_sql "INSERT INTO $DB.usertable1 VALUES (\"a\", \"b\");"
29+
run_sql "INSERT INTO $DB.usertable1 VALUES (\"aa\", \"b\");"
30+
31+
run_sql "CREATE TABLE $DB.usertable2 ( \
32+
YCSB_KEY varchar(64) NOT NULL, \
33+
FIELD0 varchar(1) DEFAULT NULL, \
34+
PRIMARY KEY (YCSB_KEY) \
35+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"
36+
37+
run_sql "INSERT INTO $DB.usertable2 VALUES (\"c\", \"d\");"
38+
# backup db
39+
echo "backup start..."
40+
run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB"
41+
42+
run_sql "DROP DATABASE $DB;"
43+
44+
# restore db
45+
echo "restore start..."
46+
run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR
47+
48+
table_count=$(run_sql "use $DB; show tables;" | grep "Tables_in" | wc -l)
49+
if [ "$table_count" -ne "2" ];then
50+
echo "TEST: [$TEST_NAME] failed!"
51+
exit 1
52+
fi
53+
54+
# restore db again
55+
echo "restore start..."
56+
LOG_OUTPUT=$(run_br restore db --db "$DB" -s "local://$TEST_DIR/$DB" --pd "$PD_ADDR" 2>&1 || true)
57+
58+
# Check if the log contains 'ErrTableAlreadyExisted'
59+
if ! echo "$LOG_OUTPUT" | grep -q "BR:Restore:ErrTablesAlreadyExisted"; then
60+
echo "Error: 'ErrTableAlreadyExisted' not found in logs."
61+
echo "Log output:"
62+
echo "$LOG_OUTPUT"
63+
exit 1
64+
else
65+
echo "restore failed as expect"
66+
fi
67+
68+
run_sql "DROP DATABASE $DB;"

br/tests/br_incompatible_tidb_config/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_
5454
run_sql "drop schema $DB;"
5555
# restore with ddl(create table) job one by one
5656
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" --ddl-batch-size=1
57-
57+
run_sql "drop schema $DB;"
5858
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_TABLE" --ddl-batch-size=1
5959

6060
# restore
6161
run_sql "drop schema $DB;"
6262
# restore with batch create table
6363
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" --ddl-batch-size=128
64-
64+
run_sql "drop schema $DB;"
6565
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_TABLE" --ddl-batch-size=128
6666

6767
run_sql "drop schema $DB;"

br/tests/run_group_br_tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ mkdir -p $COV_DIR
2121
declare -A groups
2222
groups=(
2323
["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"
24-
["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"
24+
["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"
2525
["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"
2626
["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'
27-
["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'
27+
["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 '
2828
["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'
2929
["G06"]='br_tikv_outage br_tikv_outage3 br_restore_checkpoint br_encryption'
3030
["G07"]='br_pitr'

0 commit comments

Comments
 (0)