Skip to content

Commit 0576380

Browse files
authored
br: make table existence check unified on different br client (#58211) (#58263)
close #58168
1 parent cd63397 commit 0576380

File tree

4 files changed

+73
-11
lines changed

4 files changed

+73
-11
lines changed

br/pkg/task/restore.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,10 +859,6 @@ func runRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
859859
}
860860

861861
func checkTableExistence(ctx context.Context, mgr *conn.Mgr, tables []*metautil.Table, g glue.Glue) error {
862-
// Tasks from br clp client use other checks to validate
863-
if g.GetClient() != glue.ClientSql {
864-
return nil
865-
}
866862
message := "table already exists: "
867863
allUnique := true
868864
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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,13 @@ 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-
5857
run_sql "drop schema $DB;"
5958
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_TABLE" --ddl-batch-size=1
6059

6160
# restore
6261
run_sql "drop schema $DB;"
6362
# restore with batch create table
6463
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" --ddl-batch-size=128
65-
6664
run_sql "drop schema $DB;"
6765
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_TABLE" --ddl-batch-size=128
6866

0 commit comments

Comments
 (0)