|
| 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