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

Commit

Permalink
cherry pick #1512 to release-2.0 (#1535)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Apr 9, 2021
1 parent 1e23b34 commit 11fad2f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions _utils/terror_gen/errors_release.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ ErrSyncerReplaceEvent,[code=36064:class=sync-unit:scope=internal:level=high]
ErrSyncerOperatorNotExist,[code=36065:class=sync-unit:scope=internal:level=low], "Message: error operator not exist, position: %s"
ErrSyncerReplaceEventNotExist,[code=36066:class=sync-unit:scope=internal:level=high], "Message: replace event not exist, location: %s"
ErrSyncerParseDDL,[code=36067:class=sync-unit:scope=internal:level=high], "Message: parse DDL: %s, Workaround: Please confirm your DDL statement is correct and needed. For TiDB compatible DDL, see https://docs.pingcap.com/tidb/stable/mysql-compatibility#ddl. You can use `handle-error` command to skip or replace the DDL or add a binlog filter rule to ignore it if the DDL is not needed."
ErrSyncerUnsupportedStmt,[code=36068:class=sync-unit:scope=internal:level=high], "Message: `%s` statement not supported in %s mode"
ErrMasterSQLOpNilRequest,[code=38001:class=dm-master:scope=internal:level=medium], "Message: nil request not valid"
ErrMasterSQLOpNotSupport,[code=38002:class=dm-master:scope=internal:level=medium], "Message: op %s not supported"
ErrMasterSQLOpWithoutSharding,[code=38003:class=dm-master:scope=internal:level=medium], "Message: operate request without --sharding specified not valid"
Expand Down
6 changes: 6 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,12 @@ description = ""
workaround = "Please confirm your DDL statement is correct and needed. For TiDB compatible DDL, see https://docs.pingcap.com/tidb/stable/mysql-compatibility#ddl. You can use `handle-error` command to skip or replace the DDL or add a binlog filter rule to ignore it if the DDL is not needed."
tags = ["internal", "high"]

[error.DM-sync-unit-36068]
message = "`%s` statement not supported in %s mode"
description = ""
workaround = ""
tags = ["internal", "high"]

[error.DM-dm-master-38001]
message = "nil request not valid"
description = ""
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,6 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07 h1:oI+RNwuC9jF2g2lP0u0cVEEZrc/AYBCuFdvwrLWM/6Q=
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07/go.mod h1:yFdBgwXP24JziuRl2NMUahT7nGLNOKi1SIiFxMttVD4=
github.com/siddontang/go-log v0.0.0-20190221022429-1e957dd83bed h1:KMgQoLJGCq1IoZpLZE3AIffh9veYWoVlsvA4ib55TMM=
github.com/siddontang/go-log v0.0.0-20190221022429-1e957dd83bed/go.mod h1:yFdBgwXP24JziuRl2NMUahT7nGLNOKi1SIiFxMttVD4=
Expand Down
2 changes: 2 additions & 0 deletions pkg/terror/error_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ const (
codeSyncerOperatorNotExist
codeSyncerReplaceEventNotExist
codeSyncerParseDDL
codeSyncerUnsupportedStmt
)

// DM-master error code
Expand Down Expand Up @@ -999,6 +1000,7 @@ var (
ErrSyncerOperatorNotExist = New(codeSyncerOperatorNotExist, ClassSyncUnit, ScopeInternal, LevelLow, "error operator not exist, position: %s", "")
ErrSyncerReplaceEventNotExist = New(codeSyncerReplaceEventNotExist, ClassSyncUnit, ScopeInternal, LevelHigh, "replace event not exist, location: %s", "")
ErrSyncerParseDDL = New(codeSyncerParseDDL, ClassSyncUnit, ScopeInternal, LevelHigh, "parse DDL: %s", "Please confirm your DDL statement is correct and needed. For TiDB compatible DDL, see https://docs.pingcap.com/tidb/stable/mysql-compatibility#ddl. You can use `handle-error` command to skip or replace the DDL or add a binlog filter rule to ignore it if the DDL is not needed.")
ErrSyncerUnsupportedStmt = New(codeSyncerUnsupportedStmt, ClassSyncUnit, ScopeInternal, LevelHigh, "`%s` statement not supported in %s mode", "")

// DM-master error
ErrMasterSQLOpNilRequest = New(codeMasterSQLOpNilRequest, ClassDMMaster, ScopeInternal, LevelMedium, "nil request not valid", "")
Expand Down
2 changes: 2 additions & 0 deletions syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,8 @@ func (s *Syncer) handleQueryEvent(ev *replication.QueryEvent, ec eventContext, o
case *ast.TruncateTableStmt:
ec.tctx.L().Info("ignore truncate table statement in shard group", zap.String("event", "query"), zap.String("statement", sqlDDL))
continue
case *ast.RenameTableStmt:
return terror.ErrSyncerUnsupportedStmt.Generate("RENAME TABLE", config.ShardOptimistic)
}
}

Expand Down
43 changes: 43 additions & 0 deletions tests/shardddl1/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,48 @@ function DM_035() {
run_case 035 "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic"
}

function DM_RENAME_TABLE_CASE() {
run_sql_source1 "insert into ${shardddl1}.${tb1} values(1);"
run_sql_source2 "insert into ${shardddl1}.${tb1} values(2);"
run_sql_source2 "insert into ${shardddl1}.${tb2} values(3);"

run_sql_source1 "alter table ${shardddl1}.${tb1} add column a int;"
run_sql_source2 "alter table ${shardddl1}.${tb1} add column a int;"
run_sql_source2 "alter table ${shardddl1}.${tb2} add column a int;"

run_sql_source1 "insert into ${shardddl1}.${tb1} values(4,4);"
run_sql_source2 "insert into ${shardddl1}.${tb1} values(5,5);"
run_sql_source2 "insert into ${shardddl1}.${tb2} values(6,6);"

run_sql_source1 "rename table ${shardddl1}.${tb1} to ${shardddl1}.${tb3};"
run_sql_source2 "rename table ${shardddl1}.${tb1} to ${shardddl1}.${tb3};"
run_sql_source2 "rename table ${shardddl1}.${tb2} to ${shardddl1}.${tb4};"

run_sql_source1 "insert into ${shardddl1}.${tb3} values(7,7)"
run_sql_source2 "insert into ${shardddl1}.${tb3} values(8,8);"
run_sql_source2 "insert into ${shardddl1}.${tb4} values(9,9);"

run_sql_source1 "alter table ${shardddl1}.${tb3} add column b int;"
run_sql_source2 "alter table ${shardddl1}.${tb3} add column b int;"
run_sql_source2 "alter table ${shardddl1}.${tb4} add column b int;"

run_sql_source1 "insert into ${shardddl1}.${tb3} values(10,10,10)"
run_sql_source2 "insert into ${shardddl1}.${tb3} values(11,11,11);"
run_sql_source2 "insert into ${shardddl1}.${tb4} values(12,12,12);"

if [[ "$1" = "pessimistic" ]]; then
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
else
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status test" \
"\`RENAME TABLE\` statement not supported in $1 mode" 2
fi
}

function DM_RENAME_TABLE() {
run_case RENAME_TABLE "double-source-pessimistic" "init_table 111 211 212" "clean_table" "pessimistic"
run_case RENAME_TABLE "double-source-optimistic" "init_table 111 211 212" "clean_table" "optimistic"
}

function DM_RENAME_COLUMN_OPTIMISTIC_CASE() {
run_sql_source1 "insert into ${shardddl1}.${tb1} values(1,'aaa');"
Expand Down Expand Up @@ -665,6 +707,7 @@ function run() {
DM_${i}
sleep 1
done
DM_RENAME_TABLE
DM_RENAME_COLUMN_OPTIMISTIC
DM_RECOVER_LOCK
}
Expand Down

0 comments on commit 11fad2f

Please sign in to comment.