Skip to content

Commit

Permalink
br/stream: allow pitr to create oversized indices (#58433)
Browse files Browse the repository at this point in the history
close #58430
  • Loading branch information
YuJuncen authored Dec 24, 2024
1 parent f2db9c4 commit 384f858
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion br/pkg/task/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestUrlNoQuery(t *testing.T) {

func TestTiDBConfigUnchanged(t *testing.T) {
cfg := config.GetGlobalConfig()
restoreConfig := enableTiDBConfig()
restoreConfig := tweakLocalConfForRestore()
require.NotEqual(t, config.GetGlobalConfig(), cfg)
restoreConfig()
require.Equal(t, config.GetGlobalConfig(), cfg)
Expand Down
6 changes: 3 additions & 3 deletions br/pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ func runSnapshotRestore(c context.Context, mgr *conn.Mgr, g glue.Glue, cmdName s
}

// pre-set TiDB config for restore
restoreDBConfig := enableTiDBConfig()
restoreDBConfig := tweakLocalConfForRestore()
defer restoreDBConfig()

if client.GetSupportPolicy() {
Expand Down Expand Up @@ -1407,9 +1407,9 @@ func filterRestoreFiles(
return
}

// enableTiDBConfig tweaks some of configs of TiDB to make the restore progress go well.
// tweakLocalConfForRestore tweaks some of configs of TiDB to make the restore progress go well.
// return a function that could restore the config to origin.
func enableTiDBConfig() func() {
func tweakLocalConfForRestore() func() {
restoreConfig := config.RestoreFunc()
config.UpdateGlobal(func(conf *config.Config) {
// set max-index-length before execute DDLs and create tables
Expand Down
3 changes: 3 additions & 0 deletions br/pkg/task/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,9 @@ func restoreStream(
ctx, cancelFn := context.WithCancel(c)
defer cancelFn()

restoreCfg := tweakLocalConfForRestore()
defer restoreCfg()

if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
span1 := span.Tracer().StartSpan(
"restoreStream",
Expand Down
11 changes: 11 additions & 0 deletions br/tests/br_pitr/config/tidb-max-index-length.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# config of tidb

max-index-length = 12288

[security]
ssl-ca = "/tmp/backup_restore_test/certs/ca.pem"
ssl-cert = "/tmp/backup_restore_test/certs/tidb.pem"
ssl-key = "/tmp/backup_restore_test/certs/tidb.key"
cluster-ssl-ca = "/tmp/backup_restore_test/certs/ca.pem"
cluster-ssl-cert = "/tmp/backup_restore_test/certs/tidb.pem"
cluster-ssl-key = "/tmp/backup_restore_test/certs/tidb.key"
3 changes: 3 additions & 0 deletions br/tests/br_pitr/incremental_data/ingest_repair.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ ALTER TABLE test.pairs9 CHANGE y y2 varchar(20);

-- test partition
ALTER TABLE test.pairs10 ADD INDEX i1(y);


CREATE INDEX huge ON test.huge_idx(blob1, blob2);
4 changes: 3 additions & 1 deletion br/tests/br_pitr/prepare_data/ingest_repair.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ INSERT INTO test.pairs10 VALUES (1,1,"1"),(2,2,"2"),(3,3,"3"),(4,4,"4"),(5,5,"5"
-- test no need to repair
CREATE TABLE test.pairs11(x int auto_increment primary key, y int DEFAULT RAND(), z int DEFAULT RAND());
INSERT INTO test.pairs11 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),();
ALTER TABLE test.pairs11 ADD UNIQUE KEY u1(x, y);
ALTER TABLE test.pairs11 ADD UNIQUE KEY u1(x, y);

CREATE TABLE test.huge_idx(id int AUTO_INCREMENT, blob1 varchar(1000), blob2 varchar(1000));
26 changes: 14 additions & 12 deletions br/tests/br_pitr/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ PREFIX="pitr_backup" # NOTICE: don't start with 'br' because `restart services`
res_file="$TEST_DIR/sql_res.$TEST_NAME.txt"
TASK_NAME="br_pitr"

restart_services_allowing_huge_index() {
echo "restarting services with huge indices enabled..."
stop_services
start_services --tidb-cfg "$CUR/config/tidb-max-index-length.toml"
echo "restart services done..."
}

# start a new cluster
echo "restart a services"
restart_services
restart_services_allowing_huge_index

# prepare the data
echo "prepare the data"
Expand Down Expand Up @@ -92,8 +98,7 @@ check_result() {
}

# start a new cluster
echo "restart services"
restart_services
restart_services_allowing_huge_index

# non-compliant operation
echo "non compliant operation"
Expand All @@ -108,13 +113,12 @@ fi
echo "run pitr"
run_sql "DROP DATABASE __TiDB_BR_Temporary_Log_Restore_Checkpoint;"
run_sql "DROP DATABASE __TiDB_BR_Temporary_Custom_SST_Restore_Checkpoint;"
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
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 )

check_result

# start a new cluster for incremental + log
echo "restart services"
restart_services
restart_services_allowing_huge_index

echo "run snapshot restore#2"
run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/$PREFIX/full"
Expand All @@ -126,7 +130,7 @@ check_result

# start a new cluster for incremental + log
echo "restart services"
restart_services
restart_services_allowing_huge_index

echo "run snapshot restore#3"
run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/$PREFIX/full"
Expand All @@ -140,8 +144,7 @@ if [ $restore_fail -ne 1 ]; then
fi

# start a new cluster for corruption
echo "restart a services"
restart_services
restart_services_allowing_huge_index

file_corruption() {
echo "corrupt the whole log files"
Expand All @@ -167,8 +170,7 @@ if [ $restore_fail -ne 1 ]; then
fi

# start a new cluster for corruption
echo "restart a services"
restart_services
restart_services_allowing_huge_index

file_lost() {
echo "lost the whole log files"
Expand Down

0 comments on commit 384f858

Please sign in to comment.