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

Commit

Permalink
enable tidb config by default (#230)
Browse files Browse the repository at this point in the history
* enable tidb config by default
  • Loading branch information
3pointer authored Apr 8, 2020
1 parent 7de169d commit a838be7
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 50 deletions.
26 changes: 18 additions & 8 deletions pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
42 changes: 0 additions & 42 deletions tests/br_alter_pk_server/run.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
lease = "360s"

alter-primary-key = true

max-index-length = 12288

98 changes: 98 additions & 0 deletions tests/br_incompatible_tidb_config/run.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a838be7

Please sign in to comment.