diff --git a/pkg/task/restore.go b/pkg/task/restore.go index 9dce5139e..16061bd94 100644 --- a/pkg/task/restore.go +++ b/pkg/task/restore.go @@ -148,16 +148,11 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf if err != nil { return err } - // execute DDL first - // set max-index-length before execute DDLs and create tables - // we set this value to max(3072*4), otherwise we might not restore table - // when upstream and downstream both set this value greater than default(3072) - conf := config.GetGlobalConfig() - conf.MaxIndexLength = config.DefMaxOfMaxIndexLength - config.StoreGlobalConfig(conf) - log.Warn("set max-index-length to max(3072*4) to skip check index length in DDL") + // pre-set TiDB config for restore + enableTiDBConfig() + // execute DDL first err = client.ExecDDLs(ddlJobs) if err != nil { return errors.Trace(err) @@ -467,3 +462,18 @@ func RunRestoreTiflashReplica(c context.Context, g glue.Glue, cmdName string, cf summary.SetSuccessStatus(true) return nil } + +func enableTiDBConfig() { + // set max-index-length before execute DDLs and create tables + // we set this value to max(3072*4), otherwise we might not restore table + // when upstream and downstream both set this value greater than default(3072) + conf := config.GetGlobalConfig() + conf.MaxIndexLength = config.DefMaxOfMaxIndexLength + log.Warn("set max-index-length to max(3072*4) to skip check index length in DDL") + + // set this to true for some auto random DDL execute normally during incremental restore + conf.Experimental.AllowAutoRandom = true + conf.Experimental.AllowsExpressionIndex = true + + config.StoreGlobalConfig(conf) +} diff --git a/tests/br_alter_pk_server/run.sh b/tests/br_alter_pk_server/run.sh deleted file mode 100755 index 6485a43be..000000000 --- a/tests/br_alter_pk_server/run.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# -# Copyright 2020 PingCAP, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eu - -cur=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -source $cur/../_utils/run_services - -DB="$TEST_NAME" - -# prepare database -echo "Restart cluster with alter-primary-key = true" -start_services "$cur" - -run_sql "drop schema if exists $DB;" -run_sql "create schema $DB;" - -run_sql "create table $DB.a (a int primary key, b int unique);" -run_sql "insert into $DB.a values (42, 42);" - -# backup -run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB" - -# restore -run_sql "drop schema $DB;" -run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB" - -run_sql "drop schema $DB;" -echo "Restart service with alter-primary-key = false" -start_services diff --git a/tests/br_alter_pk_server/config/tidb.toml b/tests/br_incompatible_tidb_config/config/tidb.toml similarity index 87% rename from tests/br_alter_pk_server/config/tidb.toml rename to tests/br_incompatible_tidb_config/config/tidb.toml index 30b7d4869..f649c2a28 100644 --- a/tests/br_alter_pk_server/config/tidb.toml +++ b/tests/br_incompatible_tidb_config/config/tidb.toml @@ -6,3 +6,6 @@ lease = "360s" alter-primary-key = true + +max-index-length = 12288 + diff --git a/tests/br_alter_pk_server/config/tikv.toml b/tests/br_incompatible_tidb_config/config/tikv.toml similarity index 100% rename from tests/br_alter_pk_server/config/tikv.toml rename to tests/br_incompatible_tidb_config/config/tikv.toml diff --git a/tests/br_incompatible_tidb_config/run.sh b/tests/br_incompatible_tidb_config/run.sh new file mode 100755 index 000000000..5fd0b24b6 --- /dev/null +++ b/tests/br_incompatible_tidb_config/run.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# +# Copyright 2020 PingCAP, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eu + +cur=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source $cur/../_utils/run_services + +DB="$TEST_NAME" + +# prepare database +echo "Restart cluster with alter-primary-key = true, max-index-length=12288" +start_services "$cur" + +run_sql "drop schema if exists $DB;" +run_sql "create schema $DB;" + +# test alter pk issue https://github.com/pingcap/br/issues/215 +TABLE="t1" + +run_sql "create table $DB.$TABLE (a int primary key, b int unique);" +run_sql "insert into $DB.$TABLE values (42, 42);" + +# backup +run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" + +# restore +run_sql "drop schema $DB;" +run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" + +run_sql "drop schema $DB;" +run_sql "create schema $DB;" + +# test max-index-length issue https://github.com/pingcap/br/issues/217 +TABLE="t2" +run_sql "create table $DB.$TABLE (a varchar(3072) primary key);" +run_sql "insert into $DB.$TABLE values ('42');" + +# backup +run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" + +# restore +run_sql "drop schema $DB;" +run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" + +run_sql "drop schema $DB;" + +# we need set auto_random to true and remove alter-primary-key otherwise we will get error +# invalid config allow-auto-random is unavailable when alter-primary-key is enabled + +# enable column attribute `auto_random` to be defined on the primary key column. +cat > $cur/config/tidb.toml << EOF +[experimental] +allow-auto-random = true +EOF + +echo "Restart cluster with allow-auto-random=true" +start_services "$cur" + +# test auto random issue issue https://github.com/pingcap/br/issues/228 +TABLE="t3" +INCREMENTAL_TABLE="t3inc" +run_sql "create schema $DB;" +run_sql "create table $DB.$TABLE (a int(11) NOT NULL /*T!30100 AUTO_RANDOM(5) */, PRIMARY KEY (a))" +run_sql "insert into $DB.$TABLE values ('42');" + +# Full backup +run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" + +run_sql "create table $DB.$INCREMENTAL_TABLE (a int(11) NOT NULL /*T!30100 AUTO_RANDOM(5) */, PRIMARY KEY (a))" +run_sql "insert into $DB.$INCREMENTAL_TABLE values ('42');" + +# incremental backup test for execute DDL +run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_TABLE" + +run_sql "drop schema $DB;" + +# full restore +run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$TABLE" +# incremental restore +run_br --pd $PD_ADDR restore db --db "$DB" -s "local://$TEST_DIR/$DB$INCREMENTAL_TABLE" + +run_sql "drop schema $DB;" + +echo "Restart service with normal" +start_services