Skip to content

Commit

Permalink
task, tests: cherry-picking pingcap#509
Browse files Browse the repository at this point in the history
Signed-off-by: Hillium <maruruku@stu.csust.edu.cn>
  • Loading branch information
YuJuncen authored and Hillium committed Sep 18, 2020
1 parent 6085eb9 commit a3afce3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
10 changes: 10 additions & 0 deletions pkg/task/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package task
import (
"fmt"

"github.com/pingcap/tidb/config"

. "github.com/pingcap/check"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -37,3 +39,11 @@ func (*testCommonSuite) TestUrlNoQuery(c *C) {
c.Assert(field.Key, Equals, flagStorage)
c.Assert(field.Interface.(fmt.Stringer).String(), Equals, "s3://some/what")
}

func (s *testCommonSuite) TestTiDBConfigUnchanged(c *C) {
cfg := config.GetGlobalConfig()
restoreConfig := enableTiDBConfig()
c.Assert(cfg, Not(DeepEquals), config.GetGlobalConfig())
restoreConfig()
c.Assert(cfg, DeepEquals, config.GetGlobalConfig())
}
33 changes: 18 additions & 15 deletions pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
ddlJobs := restore.FilterDDLJobs(client.GetDDLJobs(), tables)

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

// execute DDL first
err = client.ExecDDLs(ddlJobs)
Expand Down Expand Up @@ -413,21 +414,23 @@ func RunRestoreTiflashReplica(c context.Context, g glue.Glue, cmdName string, cf
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")

// we need set this to true, since all create table DDLs will create with tableInfo
// and we can handle alter drop pk/add pk DDLs with no impact
conf.AlterPrimaryKey = true

conf.Experimental.AllowsExpressionIndex = true
// enableTiDBConfig 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() {
restoreConfig := config.RestoreFunc()
config.UpdateGlobal(func(conf *config.Config) {
// 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.MaxIndexLength = config.DefMaxOfMaxIndexLength
log.Warn("set max-index-length to max(3072*4) to skip check index length in DDL")

// we need set this to true, since all create table DDLs will create with tableInfo
// and we can handle alter drop pk/add pk DDLs with no impact
conf.AlterPrimaryKey = true
})

config.StoreGlobalConfig(conf)
return restoreConfig
}

// restoreTableStream blocks current goroutine and restore a stream of tables,
Expand Down
5 changes: 4 additions & 1 deletion tests/br_db/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
set -eu
DB="$TEST_NAME"

old_conf=$(run_sql "show config where name = 'alter-primary-key'")
run_sql "CREATE DATABASE $DB;"

run_sql "CREATE TABLE $DB.usertable1 ( \
Expand All @@ -34,7 +35,6 @@ run_sql "CREATE TABLE $DB.usertable2 ( \
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"

run_sql "INSERT INTO $DB.usertable2 VALUES (\"c\", \"d\");"

# backup db
echo "backup start..."
run_br --pd $PD_ADDR backup db --db "$DB" -s "local://$TEST_DIR/$DB" --ratelimit 5 --concurrency 4
Expand All @@ -56,4 +56,7 @@ echo "testing DDL query..."
curl 127.0.0.1:10080/ddl/history | grep -E '/\*from\(br\)\*/CREATE TABLE'
curl 127.0.0.1:10080/ddl/history | grep -E '/\*from\(br\)\*/CREATE DATABASE'

# test whether we have changed the cluster config.
test "$old_conf" = "$(run_sql "show config where name = 'alter-primary-key'")"

run_sql "DROP DATABASE $DB;"
4 changes: 4 additions & 0 deletions tests/br_full/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set -eu
DB="$TEST_NAME"
TABLE="usertable"
DB_COUNT=3
old_conf=$(run_sql "show config where name = 'alter-primary-key'")

for i in $(seq $DB_COUNT); do
run_sql "CREATE DATABASE $DB${i};"
Expand Down Expand Up @@ -71,6 +72,9 @@ for ct in lz4 zstd; do
fi
done

# test whether we have changed the cluster config.
test "$old_conf" = "$(run_sql "show config where name = 'alter-primary-key'")"

for i in $(seq $DB_COUNT); do
run_sql "DROP DATABASE $DB${i};"
done

0 comments on commit a3afce3

Please sign in to comment.