Skip to content

Commit fa65d38

Browse files
YuJuncenti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#58433
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 80db670 commit fa65d38

File tree

7 files changed

+122
-6
lines changed

7 files changed

+122
-6
lines changed

br/pkg/task/common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestUrlNoQuery(t *testing.T) {
8787

8888
func TestTiDBConfigUnchanged(t *testing.T) {
8989
cfg := config.GetGlobalConfig()
90-
restoreConfig := enableTiDBConfig()
90+
restoreConfig := tweakLocalConfForRestore()
9191
require.NotEqual(t, config.GetGlobalConfig(), cfg)
9292
restoreConfig()
9393
require.Equal(t, config.GetGlobalConfig(), cfg)

br/pkg/task/restore.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ func runRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
922922
}
923923

924924
// pre-set TiDB config for restore
925-
restoreDBConfig := enableTiDBConfig()
925+
restoreDBConfig := tweakLocalConfForRestore()
926926
defer restoreDBConfig()
927927

928928
if client.GetSupportPolicy() {
@@ -1214,6 +1214,7 @@ func filterRestoreFiles(
12141214
return
12151215
}
12161216

1217+
<<<<<<< HEAD
12171218
// restorePreWork executes some prepare work before restore.
12181219
// TODO make this function returns a restore post work.
12191220
func restorePreWork(ctx context.Context, client *restore.Client, mgr *conn.Mgr, switchToImport bool) (pdutil.UndoFunc, *pdutil.ClusterConfig, error) {
@@ -1250,8 +1251,11 @@ func restorePostWork(
12501251
}
12511252

12521253
// enableTiDBConfig tweaks some of configs of TiDB to make the restore progress go well.
1254+
=======
1255+
// tweakLocalConfForRestore tweaks some of configs of TiDB to make the restore progress go well.
1256+
>>>>>>> 384f858a6c8 (br/stream: allow pitr to create oversized indices (#58433))
12531257
// return a function that could restore the config to origin.
1254-
func enableTiDBConfig() func() {
1258+
func tweakLocalConfForRestore() func() {
12551259
restoreConfig := config.RestoreFunc()
12561260
config.UpdateGlobal(func(conf *config.Config) {
12571261
// set max-index-length before execute DDLs and create tables

br/pkg/task/stream.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,9 @@ func restoreStream(
12631263
ctx, cancelFn := context.WithCancel(c)
12641264
defer cancelFn()
12651265

1266+
restoreCfg := tweakLocalConfForRestore()
1267+
defer restoreCfg()
1268+
12661269
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
12671270
span1 := span.Tracer().StartSpan(
12681271
"restoreStream",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# config of tidb
2+
3+
max-index-length = 12288
4+
5+
[security]
6+
ssl-ca = "/tmp/backup_restore_test/certs/ca.pem"
7+
ssl-cert = "/tmp/backup_restore_test/certs/tidb.pem"
8+
ssl-key = "/tmp/backup_restore_test/certs/tidb.key"
9+
cluster-ssl-ca = "/tmp/backup_restore_test/certs/ca.pem"
10+
cluster-ssl-cert = "/tmp/backup_restore_test/certs/tidb.pem"
11+
cluster-ssl-key = "/tmp/backup_restore_test/certs/tidb.key"

br/tests/br_pitr/incremental_data/ingest_repair.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ ALTER TABLE test.pairs9 CHANGE y y2 varchar(20);
4646

4747
-- test partition
4848
ALTER TABLE test.pairs10 ADD INDEX i1(y);
49+
50+
51+
CREATE INDEX huge ON test.huge_idx(blob1, blob2);

br/tests/br_pitr/prepare_data/ingest_repair.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ INSERT INTO test.pairs10 VALUES (1,1,"1"),(2,2,"2"),(3,3,"3"),(4,4,"4"),(5,5,"5"
4343
-- test no need to repair
4444
CREATE TABLE test.pairs11(x int auto_increment primary key, y int DEFAULT RAND(), z int DEFAULT RAND());
4545
INSERT INTO test.pairs11 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),();
46-
ALTER TABLE test.pairs11 ADD UNIQUE KEY u1(x, y);
46+
ALTER TABLE test.pairs11 ADD UNIQUE KEY u1(x, y);
47+
48+
CREATE TABLE test.huge_idx(id int AUTO_INCREMENT, blob1 varchar(1000), blob2 varchar(1000));

br/tests/br_pitr/run.sh

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ CUR=$(cd `dirname $0`; pwd)
2222
PREFIX="pitr_backup" # NOTICE: don't start with 'br' because `restart services` would remove file/directory br*.
2323
res_file="$TEST_DIR/sql_res.$TEST_NAME.txt"
2424

25+
restart_services_allowing_huge_index() {
26+
echo "restarting services with huge indices enabled..."
27+
stop_services
28+
start_services --tidb-cfg "$CUR/config/tidb-max-index-length.toml"
29+
echo "restart services done..."
30+
}
31+
2532
# start a new cluster
26-
echo "restart a services"
27-
restart_services
33+
restart_services_allowing_huge_index
2834

2935
# prepare the data
3036
echo "prepare the data"
@@ -93,11 +99,16 @@ done
9399
# ...
94100

95101
# start a new cluster
102+
<<<<<<< HEAD
96103
echo "restart a services"
97104
restart_services
105+
=======
106+
restart_services_allowing_huge_index
107+
>>>>>>> 384f858a6c8 (br/stream: allow pitr to create oversized indices (#58433))
98108

99109
# PITR restore
100110
echo "run pitr"
111+
<<<<<<< HEAD
101112
run_br --pd $PD_ADDR restore point -s "local://$TEST_DIR/$PREFIX/log" --full-backup-storage "local://$TEST_DIR/$PREFIX/full" > $res_file 2>&1
102113

103114
# check something in downstream cluster
@@ -112,3 +123,85 @@ expect_delete_range=$(($incremental_delete_range_count-$prepare_delete_range_cou
112123
check_contains "DELETE_RANGE_CNT: $expect_delete_range"
113124
## check feature compatibility between PITR and accelerate indexing
114125
bash $CUR/check/check_ingest_repair.sh
126+
=======
127+
run_sql "DROP DATABASE __TiDB_BR_Temporary_Log_Restore_Checkpoint;"
128+
run_sql "DROP DATABASE __TiDB_BR_Temporary_Custom_SST_Restore_Checkpoint;"
129+
run_br --pd $PD_ADDR restore point -s "local://$TEST_DIR/$PREFIX/log" --full-backup-storage "local://$TEST_DIR/$PREFIX/full" > $res_file 2>&1 || ( cat $res_file && exit 1 )
130+
131+
check_result
132+
133+
# start a new cluster for incremental + log
134+
restart_services_allowing_huge_index
135+
136+
echo "run snapshot restore#2"
137+
run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/$PREFIX/full"
138+
139+
echo "run incremental restore + log restore"
140+
run_br --pd $PD_ADDR restore point -s "local://$TEST_DIR/$PREFIX/log" --full-backup-storage "local://$TEST_DIR/$PREFIX/inc" > $res_file 2>&1
141+
142+
check_result
143+
144+
# start a new cluster for incremental + log
145+
echo "restart services"
146+
restart_services_allowing_huge_index
147+
148+
echo "run snapshot restore#3"
149+
run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/$PREFIX/full"
150+
151+
echo "run incremental restore but failed"
152+
restore_fail=0
153+
run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/$PREFIX/inc_fail" || restore_fail=1
154+
if [ $restore_fail -ne 1 ]; then
155+
echo 'pitr success on incremental restore'
156+
exit 1
157+
fi
158+
159+
# start a new cluster for corruption
160+
restart_services_allowing_huge_index
161+
162+
file_corruption() {
163+
echo "corrupt the whole log files"
164+
for filename in $(find $TEST_DIR/$PREFIX/log -regex ".*\.log" | grep -v "schema-meta"); do
165+
echo "corrupt the log file $filename"
166+
filename_temp=$filename"_temp"
167+
echo "corruption" > $filename_temp
168+
cat $filename >> $filename_temp
169+
mv $filename_temp $filename
170+
truncate -s -11 $filename
171+
done
172+
}
173+
174+
# file corruption
175+
file_corruption
176+
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/utils/set-remaining-attempts-to-one=return(true)"
177+
restore_fail=0
178+
run_br --pd $PD_ADDR restore point -s "local://$TEST_DIR/$PREFIX/log" --full-backup-storage "local://$TEST_DIR/$PREFIX/full" || restore_fail=1
179+
export GO_FAILPOINTS=""
180+
if [ $restore_fail -ne 1 ]; then
181+
echo 'pitr success on file corruption'
182+
exit 1
183+
fi
184+
185+
# start a new cluster for corruption
186+
restart_services_allowing_huge_index
187+
188+
file_lost() {
189+
echo "lost the whole log files"
190+
for filename in $(find $TEST_DIR/$PREFIX/log -regex ".*\.log" | grep -v "schema-meta"); do
191+
echo "lost the log file $filename"
192+
filename_temp=$filename"_temp"
193+
mv $filename $filename_temp
194+
done
195+
}
196+
197+
# file lost
198+
file_lost
199+
export GO_FAILPOINTS="github.com/pingcap/tidb/br/pkg/utils/set-remaining-attempts-to-one=return(true)"
200+
restore_fail=0
201+
run_br --pd $PD_ADDR restore point -s "local://$TEST_DIR/$PREFIX/log" --full-backup-storage "local://$TEST_DIR/$PREFIX/full" || restore_fail=1
202+
export GO_FAILPOINTS=""
203+
if [ $restore_fail -ne 1 ]; then
204+
echo 'pitr success on file lost'
205+
exit 1
206+
fi
207+
>>>>>>> 384f858a6c8 (br/stream: allow pitr to create oversized indices (#58433))

0 commit comments

Comments
 (0)