From d1e1a8a23671f0e53da9dac8d8eb37925eb8d205 Mon Sep 17 00:00:00 2001 From: AilinKid <314806019@qq.com> Date: Mon, 7 Dec 2020 18:51:47 +0800 Subject: [PATCH 1/6] add a switch for multi schema change & make it compatible with old test cases Signed-off-by: AilinKid <314806019@qq.com> --- ddl/ddl_api.go | 3 +++ session/bootstrap.go | 7 +++++++ session/session.go | 3 +++ sessionctx/variable/session.go | 6 ++++++ sessionctx/variable/sysvar.go | 1 + sessionctx/variable/tidb_vars.go | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 33c26bf4ffcc9..15a4ed733d37e 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2316,6 +2316,9 @@ func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.A } if len(validSpecs) > 1 { + if !ctx.GetSessionVars().EnableMultiSchemaChange { + return errRunMultiSchemaChanges + } if isSameTypeMultiSpecs(validSpecs) { switch validSpecs[0].Tp { case ast.AlterTableAddColumns: diff --git a/session/bootstrap.go b/session/bootstrap.go index e0abf419351be..82c1c38c4c81c 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -1335,6 +1335,13 @@ func doDMLWorks(s Session) { vVal = string(variable.DynamicOnly) } } + if v.Name == variable.TiDBEnableMultiSchemaChange { + vVal = variable.BoolOff + if flag.Lookup("test.v") != nil || flag.Lookup("check.v") != nil { + // enable multi schema change in test case for compatibility with old cases. + vVal = variable.BoolOn + } + } value := fmt.Sprintf(`("%s", "%s")`, strings.ToLower(k), vVal) values = append(values, value) } diff --git a/session/session.go b/session/session.go index 046610eee4adb..032bee29432d5 100644 --- a/session/session.go +++ b/session/session.go @@ -1815,6 +1815,8 @@ func CreateSession4TestWithOpt(store kv.Storage, opt *Opt) (Session, error) { // initialize session variables for test. s.GetSessionVars().InitChunkSize = 2 s.GetSessionVars().MaxChunkSize = 32 + // make the config variable be compatible with those old test. + s.GetSessionVars().EnableMultiSchemaChange = true } return s, err } @@ -2282,6 +2284,7 @@ var builtinGlobalVariable = []string{ variable.TiDBEnableTelemetry, variable.TiDBShardAllocateStep, variable.TiDBEnableChangeColumnType, + variable.TiDBEnableMultiSchemaChange, variable.TiDBEnableAmendPessimisticTxn, variable.TiDBMemoryUsageAlarmRatio, variable.TiDBEnableRateLimitAction, diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 29204aae4252a..4a88ad66efb39 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -572,6 +572,9 @@ type SessionVars struct { // EnableChangeColumnType is used to control whether to enable the change column type. EnableChangeColumnType bool + // EnableMultiSchemaChange is used to control whether to enable the multi schema change. + EnableMultiSchemaChange bool + // WaitSplitRegionFinish defines the split region behaviour is sync or async. WaitSplitRegionFinish bool @@ -904,6 +907,7 @@ func NewSessionVars() *SessionVars { EnableParallelApply: DefTiDBEnableParallelApply, ShardAllocateStep: DefTiDBShardAllocateStep, EnableChangeColumnType: DefTiDBChangeColumnType, + EnableMultiSchemaChange: DefTiDBMultiSchemaChange, EnableAmendPessimisticTxn: DefTiDBEnableAmendPessimisticTxn, PartitionPruneMode: *atomic2.NewString(DefTiDBPartitionPruneMode), TxnScope: config.GetGlobalConfig().TxnScope, @@ -1613,6 +1617,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error { s.ShardAllocateStep = tidbOptInt64(val, DefTiDBShardAllocateStep) case TiDBEnableChangeColumnType: s.EnableChangeColumnType = TiDBOptOn(val) + case TiDBEnableMultiSchemaChange: + s.EnableMultiSchemaChange = TiDBOptOn(val) case TiDBEnableAmendPessimisticTxn: s.EnableAmendPessimisticTxn = TiDBOptOn(val) case TiDBTxnScope: diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index ab1d0eb2cbb58..e7a972024f8bc 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -1046,6 +1046,7 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeSession, Name: TiDBDDLReorgPriority, Value: "PRIORITY_LOW"}, {Scope: ScopeGlobal, Name: TiDBMaxDeltaSchemaCount, Value: strconv.Itoa(DefTiDBMaxDeltaSchemaCount), Type: TypeUnsigned, MinValue: 100, MaxValue: 16384, AutoConvertOutOfRange: true}, {Scope: ScopeGlobal, Name: TiDBEnableChangeColumnType, Value: BoolToOnOff(DefTiDBChangeColumnType), Type: TypeBool}, + {Scope: ScopeGlobal, Name: TiDBEnableMultiSchemaChange, Value: BoolToOnOff(DefTiDBMultiSchemaChange), Type: TypeBool}, {Scope: ScopeSession, Name: TiDBForcePriority, Value: mysql.Priority2Str[DefTiDBForcePriority]}, {Scope: ScopeSession, Name: TiDBEnableRadixJoin, Value: BoolToOnOff(DefTiDBUseRadixJoin), Type: TypeBool}, {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptJoinReorderThreshold, Value: strconv.Itoa(DefTiDBOptJoinReorderThreshold), Type: TypeUnsigned, MinValue: 0, MaxValue: 63}, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 7115c4e74f7e8..dabb214569bbb 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -351,6 +351,9 @@ const ( // TiDBEnableChangeColumnType is used to control whether to enable the change column type. TiDBEnableChangeColumnType = "tidb_enable_change_column_type" + // TiDBEnableMultiSchemaChange is used to control whether to enable the multi schema change. + TiDBEnableMultiSchemaChange = "tidb_enable_multi_schema_change" + // tidb_max_delta_schema_count defines the max length of deltaSchemaInfos. // deltaSchemaInfos is a queue that maintains the history of schema changes. TiDBMaxDeltaSchemaCount = "tidb_max_delta_schema_count" @@ -557,6 +560,7 @@ const ( DefTiDBDDLErrorCountLimit = 512 DefTiDBMaxDeltaSchemaCount = 1024 DefTiDBChangeColumnType = false + DefTiDBMultiSchemaChange = false DefTiDBHashAggPartialConcurrency = ConcurrencyUnset DefTiDBHashAggFinalConcurrency = ConcurrencyUnset DefTiDBWindowConcurrency = ConcurrencyUnset From 07e64609ceb31e4f7e8cff4caee6888be6a94d49 Mon Sep 17 00:00:00 2001 From: AilinKid <314806019@qq.com> Date: Mon, 7 Dec 2020 18:58:46 +0800 Subject: [PATCH 2/6] . Signed-off-by: AilinKid <314806019@qq.com> --- session/session.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/session/session.go b/session/session.go index 032bee29432d5..d941b792fcabb 100644 --- a/session/session.go +++ b/session/session.go @@ -1815,8 +1815,6 @@ func CreateSession4TestWithOpt(store kv.Storage, opt *Opt) (Session, error) { // initialize session variables for test. s.GetSessionVars().InitChunkSize = 2 s.GetSessionVars().MaxChunkSize = 32 - // make the config variable be compatible with those old test. - s.GetSessionVars().EnableMultiSchemaChange = true } return s, err } From 4e8716459e388a5c278da8f3353d38aa79081ec8 Mon Sep 17 00:00:00 2001 From: AilinKid <314806019@qq.com> Date: Tue, 8 Dec 2020 15:07:08 +0800 Subject: [PATCH 3/6] . Signed-off-by: AilinKid <314806019@qq.com> --- ddl/ddl_api.go | 2 +- session/bootstrap.go | 4 ++-- session/session.go | 2 +- sessionctx/variable/session.go | 10 +++++----- sessionctx/variable/sysvar.go | 2 +- sessionctx/variable/tidb_vars.go | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 15a4ed733d37e..2d407fe52d98e 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2316,7 +2316,7 @@ func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.A } if len(validSpecs) > 1 { - if !ctx.GetSessionVars().EnableMultiSchemaChange { + if !ctx.GetSessionVars().EnableChangeMultiSchema { return errRunMultiSchemaChanges } if isSameTypeMultiSpecs(validSpecs) { diff --git a/session/bootstrap.go b/session/bootstrap.go index 82c1c38c4c81c..3722aaf668994 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -1335,10 +1335,10 @@ func doDMLWorks(s Session) { vVal = string(variable.DynamicOnly) } } - if v.Name == variable.TiDBEnableMultiSchemaChange { + if v.Name == variable.TiDBEnableChangeMultiSchema { vVal = variable.BoolOff if flag.Lookup("test.v") != nil || flag.Lookup("check.v") != nil { - // enable multi schema change in test case for compatibility with old cases. + // enable change multi schema in test case for compatibility with old cases. vVal = variable.BoolOn } } diff --git a/session/session.go b/session/session.go index d941b792fcabb..bcceecd561e4b 100644 --- a/session/session.go +++ b/session/session.go @@ -2282,7 +2282,7 @@ var builtinGlobalVariable = []string{ variable.TiDBEnableTelemetry, variable.TiDBShardAllocateStep, variable.TiDBEnableChangeColumnType, - variable.TiDBEnableMultiSchemaChange, + variable.TiDBEnableChangeMultiSchema, variable.TiDBEnableAmendPessimisticTxn, variable.TiDBMemoryUsageAlarmRatio, variable.TiDBEnableRateLimitAction, diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 4a88ad66efb39..799830c558056 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -572,8 +572,8 @@ type SessionVars struct { // EnableChangeColumnType is used to control whether to enable the change column type. EnableChangeColumnType bool - // EnableMultiSchemaChange is used to control whether to enable the multi schema change. - EnableMultiSchemaChange bool + // EnableChangeMultiSchema is used to control whether to enable the multi schema change. + EnableChangeMultiSchema bool // WaitSplitRegionFinish defines the split region behaviour is sync or async. WaitSplitRegionFinish bool @@ -907,7 +907,7 @@ func NewSessionVars() *SessionVars { EnableParallelApply: DefTiDBEnableParallelApply, ShardAllocateStep: DefTiDBShardAllocateStep, EnableChangeColumnType: DefTiDBChangeColumnType, - EnableMultiSchemaChange: DefTiDBMultiSchemaChange, + EnableChangeMultiSchema: DefTiDBMultiSchemaChange, EnableAmendPessimisticTxn: DefTiDBEnableAmendPessimisticTxn, PartitionPruneMode: *atomic2.NewString(DefTiDBPartitionPruneMode), TxnScope: config.GetGlobalConfig().TxnScope, @@ -1617,8 +1617,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error { s.ShardAllocateStep = tidbOptInt64(val, DefTiDBShardAllocateStep) case TiDBEnableChangeColumnType: s.EnableChangeColumnType = TiDBOptOn(val) - case TiDBEnableMultiSchemaChange: - s.EnableMultiSchemaChange = TiDBOptOn(val) + case TiDBEnableChangeMultiSchema: + s.EnableChangeMultiSchema = TiDBOptOn(val) case TiDBEnableAmendPessimisticTxn: s.EnableAmendPessimisticTxn = TiDBOptOn(val) case TiDBTxnScope: diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index e7a972024f8bc..e2ada3ea91a94 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -1046,7 +1046,7 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeSession, Name: TiDBDDLReorgPriority, Value: "PRIORITY_LOW"}, {Scope: ScopeGlobal, Name: TiDBMaxDeltaSchemaCount, Value: strconv.Itoa(DefTiDBMaxDeltaSchemaCount), Type: TypeUnsigned, MinValue: 100, MaxValue: 16384, AutoConvertOutOfRange: true}, {Scope: ScopeGlobal, Name: TiDBEnableChangeColumnType, Value: BoolToOnOff(DefTiDBChangeColumnType), Type: TypeBool}, - {Scope: ScopeGlobal, Name: TiDBEnableMultiSchemaChange, Value: BoolToOnOff(DefTiDBMultiSchemaChange), Type: TypeBool}, + {Scope: ScopeGlobal, Name: TiDBEnableChangeMultiSchema, Value: BoolToOnOff(DefTiDBMultiSchemaChange), Type: TypeBool}, {Scope: ScopeSession, Name: TiDBForcePriority, Value: mysql.Priority2Str[DefTiDBForcePriority]}, {Scope: ScopeSession, Name: TiDBEnableRadixJoin, Value: BoolToOnOff(DefTiDBUseRadixJoin), Type: TypeBool}, {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptJoinReorderThreshold, Value: strconv.Itoa(DefTiDBOptJoinReorderThreshold), Type: TypeUnsigned, MinValue: 0, MaxValue: 63}, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index dabb214569bbb..38855068e1d80 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -351,8 +351,8 @@ const ( // TiDBEnableChangeColumnType is used to control whether to enable the change column type. TiDBEnableChangeColumnType = "tidb_enable_change_column_type" - // TiDBEnableMultiSchemaChange is used to control whether to enable the multi schema change. - TiDBEnableMultiSchemaChange = "tidb_enable_multi_schema_change" + // TiDBEnableChangeMultiSchema is used to control whether to enable the change multi schema. + TiDBEnableChangeMultiSchema = "tidb_enable_change_multi_schema" // tidb_max_delta_schema_count defines the max length of deltaSchemaInfos. // deltaSchemaInfos is a queue that maintains the history of schema changes. From 446b656851fefba8549ba0a1a2e6c370bbe46b4e Mon Sep 17 00:00:00 2001 From: Arenatlx Date: Wed, 9 Dec 2020 10:57:34 +0800 Subject: [PATCH 4/6] Update sessionctx/variable/tidb_vars.go Co-authored-by: tangenta --- sessionctx/variable/tidb_vars.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 973e59550d037..32e64113d856b 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -563,7 +563,7 @@ const ( DefTiDBDDLErrorCountLimit = 512 DefTiDBMaxDeltaSchemaCount = 1024 DefTiDBChangeColumnType = false - DefTiDBMultiSchemaChange = false + DefTiDBChangeMultiSchema = false DefTiDBHashAggPartialConcurrency = ConcurrencyUnset DefTiDBHashAggFinalConcurrency = ConcurrencyUnset DefTiDBWindowConcurrency = ConcurrencyUnset From 435eab3e47aebe1608404990a184d865d069d38d Mon Sep 17 00:00:00 2001 From: Arenatlx Date: Wed, 9 Dec 2020 10:57:44 +0800 Subject: [PATCH 5/6] Update sessionctx/variable/session.go Co-authored-by: tangenta --- sessionctx/variable/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index ee0f48256843d..72d01f921286f 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -910,7 +910,7 @@ func NewSessionVars() *SessionVars { EnableParallelApply: DefTiDBEnableParallelApply, ShardAllocateStep: DefTiDBShardAllocateStep, EnableChangeColumnType: DefTiDBChangeColumnType, - EnableChangeMultiSchema: DefTiDBMultiSchemaChange, + EnableChangeMultiSchema: DefTiDBChangeMultiSchema, EnableAmendPessimisticTxn: DefTiDBEnableAmendPessimisticTxn, PartitionPruneMode: *atomic2.NewString(DefTiDBPartitionPruneMode), TxnScope: config.GetGlobalConfig().TxnScope, From edd6685db2826d5f78923b49d82fa4bbcd2f49d7 Mon Sep 17 00:00:00 2001 From: Arenatlx Date: Wed, 9 Dec 2020 10:57:55 +0800 Subject: [PATCH 6/6] Update sessionctx/variable/sysvar.go Co-authored-by: tangenta --- sessionctx/variable/sysvar.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 17df9efbb729a..ace7948bb86c8 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -1046,7 +1046,7 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeSession, Name: TiDBDDLReorgPriority, Value: "PRIORITY_LOW"}, {Scope: ScopeGlobal, Name: TiDBMaxDeltaSchemaCount, Value: strconv.Itoa(DefTiDBMaxDeltaSchemaCount), Type: TypeUnsigned, MinValue: 100, MaxValue: 16384, AutoConvertOutOfRange: true}, {Scope: ScopeGlobal, Name: TiDBEnableChangeColumnType, Value: BoolToOnOff(DefTiDBChangeColumnType), Type: TypeBool}, - {Scope: ScopeGlobal, Name: TiDBEnableChangeMultiSchema, Value: BoolToOnOff(DefTiDBMultiSchemaChange), Type: TypeBool}, + {Scope: ScopeGlobal, Name: TiDBEnableChangeMultiSchema, Value: BoolToOnOff(DefTiDBChangeMultiSchema), Type: TypeBool}, {Scope: ScopeSession, Name: TiDBForcePriority, Value: mysql.Priority2Str[DefTiDBForcePriority]}, {Scope: ScopeSession, Name: TiDBEnableRadixJoin, Value: BoolToOnOff(DefTiDBUseRadixJoin), Type: TypeBool}, {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptJoinReorderThreshold, Value: strconv.Itoa(DefTiDBOptJoinReorderThreshold), Type: TypeUnsigned, MinValue: 0, MaxValue: 63},