Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 97652ef

Browse files
authored
Merge branch 'master' into empty_region
2 parents 745c487 + a838be7 commit 97652ef

File tree

5 files changed

+119
-50
lines changed

5 files changed

+119
-50
lines changed

pkg/task/restore.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,11 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
148148
if err != nil {
149149
return err
150150
}
151-
// execute DDL first
152151

153-
// set max-index-length before execute DDLs and create tables
154-
// we set this value to max(3072*4), otherwise we might not restore table
155-
// when upstream and downstream both set this value greater than default(3072)
156-
conf := config.GetGlobalConfig()
157-
conf.MaxIndexLength = config.DefMaxOfMaxIndexLength
158-
config.StoreGlobalConfig(conf)
159-
log.Warn("set max-index-length to max(3072*4) to skip check index length in DDL")
152+
// pre-set TiDB config for restore
153+
enableTiDBConfig()
160154

155+
// execute DDL first
161156
err = client.ExecDDLs(ddlJobs)
162157
if err != nil {
163158
return errors.Trace(err)
@@ -467,3 +462,18 @@ func RunRestoreTiflashReplica(c context.Context, g glue.Glue, cmdName string, cf
467462
summary.SetSuccessStatus(true)
468463
return nil
469464
}
465+
466+
func enableTiDBConfig() {
467+
// set max-index-length before execute DDLs and create tables
468+
// we set this value to max(3072*4), otherwise we might not restore table
469+
// when upstream and downstream both set this value greater than default(3072)
470+
conf := config.GetGlobalConfig()
471+
conf.MaxIndexLength = config.DefMaxOfMaxIndexLength
472+
log.Warn("set max-index-length to max(3072*4) to skip check index length in DDL")
473+
474+
// set this to true for some auto random DDL execute normally during incremental restore
475+
conf.Experimental.AllowAutoRandom = true
476+
conf.Experimental.AllowsExpressionIndex = true
477+
478+
config.StoreGlobalConfig(conf)
479+
}

tests/br_alter_pk_server/run.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/br_alter_pk_server/config/tidb.toml renamed to tests/br_incompatible_tidb_config/config/tidb.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
lease = "360s"
77

88
alter-primary-key = true
9+
10+
max-index-length = 12288
11+
File renamed without changes.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2020 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+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eu
17+
18+
cur=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
19+
source $cur/../_utils/run_services
20+
21+
DB="$TEST_NAME"
22+
23+
# prepare database
24+
echo "Restart cluster with alter-primary-key = true, max-index-length=12288"
25+
start_services "$cur"
26+
27+
run_sql "drop schema if exists $DB;"
28+
run_sql "create schema $DB;"
29+
30+
# test alter pk issue https://github.com/pingcap/br/issues/215
31+
TABLE="t1"
32+
33+
run_sql "create table $DB.$TABLE (a int primary key, b int unique);"
34+
run_sql "insert into $DB.$TABLE values (42, 42);"
35+
36+
# backup
37+
run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE"
38+
39+
# restore
40+
run_sql "drop schema $DB;"
41+
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE"
42+
43+
run_sql "drop schema $DB;"
44+
run_sql "create schema $DB;"
45+
46+
# test max-index-length issue https://github.com/pingcap/br/issues/217
47+
TABLE="t2"
48+
run_sql "create table $DB.$TABLE (a varchar(3072) primary key);"
49+
run_sql "insert into $DB.$TABLE values ('42');"
50+
51+
# backup
52+
run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE"
53+
54+
# restore
55+
run_sql "drop schema $DB;"
56+
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE"
57+
58+
run_sql "drop schema $DB;"
59+
60+
# we need set auto_random to true and remove alter-primary-key otherwise we will get error
61+
# invalid config allow-auto-random is unavailable when alter-primary-key is enabled
62+
63+
# enable column attribute `auto_random` to be defined on the primary key column.
64+
cat > $cur/config/tidb.toml << EOF
65+
[experimental]
66+
allow-auto-random = true
67+
EOF
68+
69+
echo "Restart cluster with allow-auto-random=true"
70+
start_services "$cur"
71+
72+
# test auto random issue issue https://github.com/pingcap/br/issues/228
73+
TABLE="t3"
74+
INCREMENTAL_TABLE="t3inc"
75+
run_sql "create schema $DB;"
76+
run_sql "create table $DB.$TABLE (a int(11) NOT NULL /*T!30100 AUTO_RANDOM(5) */, PRIMARY KEY (a))"
77+
run_sql "insert into $DB.$TABLE values ('42');"
78+
79+
# Full backup
80+
run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE"
81+
82+
run_sql "create table $DB.$INCREMENTAL_TABLE (a int(11) NOT NULL /*T!30100 AUTO_RANDOM(5) */, PRIMARY KEY (a))"
83+
run_sql "insert into $DB.$INCREMENTAL_TABLE values ('42');"
84+
85+
# incremental backup test for execute DDL
86+
run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_TABLE"
87+
88+
run_sql "drop schema $DB;"
89+
90+
# full restore
91+
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE"
92+
# incremental restore
93+
run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_TABLE"
94+
95+
run_sql "drop schema $DB;"
96+
97+
echo "Restart service with normal"
98+
start_services

0 commit comments

Comments
 (0)