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

Commit

Permalink
fix unbound var and restore SQL without default charset
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Shen <overvenus@gmail.com>
  • Loading branch information
overvenus committed Feb 23, 2021
1 parent 926f421 commit 45831c6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/lightning/restore/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func createTableIfNotExistsStmt(p *parser.Parser, createTable, dbName, tblName s
}

var res strings.Builder
ctx := format.NewRestoreCtx(format.DefaultRestoreFlags, &res)
ctx := format.NewRestoreCtx(format.DefaultRestoreFlags|format.RestoreStringWithoutDefaultCharset, &res)

retStmts := make([]string, 0, len(stmts))
for _, stmt := range stmts {
Expand Down
6 changes: 3 additions & 3 deletions pkg/lightning/restore/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s *tidbSuite) TestCreateTableIfNotExistsStmt(c *C) {
c.Assert(
createTableIfNotExistsStmt("CREATE TABLE `foo`(`bar` INT(1) COMMENT 'CREATE TABLE');", "foo"),
DeepEquals,
[]string{"CREATE TABLE IF NOT EXISTS `testdb`.`foo` (`bar` INT(1) COMMENT _UTF8MB4'CREATE TABLE');"},
[]string{"CREATE TABLE IF NOT EXISTS `testdb`.`foo` (`bar` INT(1) COMMENT 'CREATE TABLE');"},
)

// upper case becomes shorter
Expand Down Expand Up @@ -141,7 +141,7 @@ func (s *tidbSuite) TestCreateTableIfNotExistsStmt(c *C) {
`, "m"),
DeepEquals,
[]string{
"SET NAMES _UTF8MB4'binary';",
"SET NAMES 'binary';",
"SET @@SESSION.`FOREIGN_KEY_CHECKS`=0;",
"CREATE TABLE IF NOT EXISTS `testdb`.`m` (`z` DOUBLE) ENGINE = InnoDB AUTO_INCREMENT = 8343230 DEFAULT CHARACTER SET = UTF8;",
},
Expand All @@ -166,7 +166,7 @@ func (s *tidbSuite) TestCreateTableIfNotExistsStmt(c *C) {
`, "m"),
DeepEquals,
[]string{
"SET NAMES _UTF8MB4'binary';",
"SET NAMES 'binary';",
"DROP TABLE IF EXISTS `testdb`.`m`;",
"DROP VIEW IF EXISTS `testdb`.`m`;",
"SET @`PREV_CHARACTER_SET_CLIENT`=@@`character_set_client`;",
Expand Down
12 changes: 7 additions & 5 deletions tests/br_full_ddl/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ DB="$TEST_NAME"
TABLE="usertable"
DDL_COUNT=10
LOG=/$TEST_DIR/backup.log
BACKUP_STAT=/$TEST_DIR/backup_stat
RESOTRE_STAT=/$TEST_DIR/restore_stat

run_sql "CREATE DATABASE $DB;"
go-ycsb load mysql -P tests/$TEST_NAME/workload -p mysql.host=$TIDB_IP -p mysql.port=$TIDB_PORT -p mysql.user=root -p mysql.db=$DB
Expand Down Expand Up @@ -94,10 +96,10 @@ fi

echo "restore full without stats..."
run_br restore full -s "local://$TEST_DIR/${DB}_disable_stats" --pd $PD_ADDR
curl $TIDB_IP:10080/stats/dump/$DB/$TABLE | jq '.columns.field0' | jq 'del(.last_update_version)' > restore_stats
curl $TIDB_IP:10080/stats/dump/$DB/$TABLE | jq '.columns.field0' | jq 'del(.last_update_version)' > $RESOTRE_STAT

# stats should not be equal because we disable stats by default.
if diff -q backup_stats restore_stats > /dev/null
if diff -q $BACKUP_STAT $RESOTRE_STAT > /dev/null
then
echo "TEST: [$TEST_NAME] fail due to stats are equal"
exit 1
Expand Down Expand Up @@ -134,13 +136,13 @@ fi

run_curl https://$TIDB_STATUS_ADDR/stats/dump/$DB/$TABLE | jq '.columns.field0 | del(.last_update_version)' > $RESOTRE_STAT

if diff -q backup_stats restore_stats > /dev/null
if diff -q $BACKUP_STAT $RESOTRE_STAT > /dev/null
then
echo "stats are equal"
else
echo "TEST: [$TEST_NAME] fail due to stats are not equal"
cat $backup_stats | head 1000
cat $restore_stats | head 1000
cat $BACKUP_STAT | head -n 1000
cat $RESOTRE_STAT | head -n 1000
exit 1
fi

Expand Down

0 comments on commit 45831c6

Please sign in to comment.