@@ -2005,20 +2005,14 @@ func (e *executor) multiSchemaChange(ctx sessionctx.Context, ti ast.Ident, info
2005
2005
Type : model .ActionMultiSchemaChange ,
2006
2006
BinlogInfo : & model.HistoryInfo {},
2007
2007
MultiSchemaInfo : info ,
2008
- ReorgMeta : nil ,
2009
2008
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
2010
2009
InvolvingSchemaInfo : involvingSchemaInfo ,
2011
2010
SQLMode : ctx .GetSessionVars ().SQLMode ,
2012
2011
}
2013
- if containsDistTaskSubJob (subJobs ) {
2014
- job .ReorgMeta , err = newReorgMetaFromVariables (job , ctx )
2015
- if err != nil {
2016
- return err
2017
- }
2018
- } else {
2019
- job .ReorgMeta = NewDDLReorgMeta (ctx )
2012
+ err = initJobReorgMetaFromVariables (job , ctx )
2013
+ if err != nil {
2014
+ return errors .Trace (err )
2020
2015
}
2021
-
2022
2016
err = checkMultiSchemaInfo (info , t )
2023
2017
if err != nil {
2024
2018
return errors .Trace (err )
@@ -2027,16 +2021,6 @@ func (e *executor) multiSchemaChange(ctx sessionctx.Context, ti ast.Ident, info
2027
2021
return e .DoDDLJob (ctx , job )
2028
2022
}
2029
2023
2030
- func containsDistTaskSubJob (subJobs []* model.SubJob ) bool {
2031
- for _ , sub := range subJobs {
2032
- if sub .Type == model .ActionAddIndex ||
2033
- sub .Type == model .ActionAddPrimaryKey {
2034
- return true
2035
- }
2036
- }
2037
- return false
2038
- }
2039
-
2040
2024
func (e * executor ) RebaseAutoID (ctx sessionctx.Context , ident ast.Ident , newBase int64 , tp autoid.AllocatorType , force bool ) error {
2041
2025
schema , t , err := e .getSchemaAndTableByIdent (ident )
2042
2026
if err != nil {
@@ -2451,10 +2435,13 @@ func (e *executor) AlterTablePartitioning(ctx sessionctx.Context, ident ast.Iden
2451
2435
TableName : t .Meta ().Name .L ,
2452
2436
Type : model .ActionAlterTablePartitioning ,
2453
2437
BinlogInfo : & model.HistoryInfo {},
2454
- ReorgMeta : NewDDLReorgMeta (ctx ),
2455
2438
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
2456
2439
SQLMode : ctx .GetSessionVars ().SQLMode ,
2457
2440
}
2441
+ err = initJobReorgMetaFromVariables (job , ctx )
2442
+ if err != nil {
2443
+ return err
2444
+ }
2458
2445
2459
2446
args := & model.TablePartitionArgs {
2460
2447
PartNames : partNames ,
@@ -2517,10 +2504,13 @@ func (e *executor) ReorganizePartitions(ctx sessionctx.Context, ident ast.Ident,
2517
2504
TableName : t .Meta ().Name .L ,
2518
2505
Type : model .ActionReorganizePartition ,
2519
2506
BinlogInfo : & model.HistoryInfo {},
2520
- ReorgMeta : NewDDLReorgMeta (ctx ),
2521
2507
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
2522
2508
SQLMode : ctx .GetSessionVars ().SQLMode ,
2523
2509
}
2510
+ err = initJobReorgMetaFromVariables (job , ctx )
2511
+ if err != nil {
2512
+ return errors .Trace (err )
2513
+ }
2524
2514
args := & model.TablePartitionArgs {
2525
2515
PartNames : partNames ,
2526
2516
PartInfo : partInfo ,
@@ -2583,10 +2573,13 @@ func (e *executor) RemovePartitioning(ctx sessionctx.Context, ident ast.Ident, s
2583
2573
TableName : meta .Name .L ,
2584
2574
Type : model .ActionRemovePartitioning ,
2585
2575
BinlogInfo : & model.HistoryInfo {},
2586
- ReorgMeta : NewDDLReorgMeta (ctx ),
2587
2576
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
2588
2577
SQLMode : ctx .GetSessionVars ().SQLMode ,
2589
2578
}
2579
+ err = initJobReorgMetaFromVariables (job , ctx )
2580
+ if err != nil {
2581
+ return errors .Trace (err )
2582
+ }
2590
2583
args := & model.TablePartitionArgs {
2591
2584
PartNames : partNames ,
2592
2585
PartInfo : partInfo ,
@@ -3385,10 +3378,13 @@ func (e *executor) RenameColumn(ctx sessionctx.Context, ident ast.Ident, spec *a
3385
3378
TableName : tbl .Meta ().Name .L ,
3386
3379
Type : model .ActionModifyColumn ,
3387
3380
BinlogInfo : & model.HistoryInfo {},
3388
- ReorgMeta : NewDDLReorgMeta (ctx ),
3389
3381
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
3390
3382
SQLMode : ctx .GetSessionVars ().SQLMode ,
3391
3383
}
3384
+ err = initJobReorgMetaFromVariables (job , ctx )
3385
+ if err != nil {
3386
+ return err
3387
+ }
3392
3388
3393
3389
args := & model.ModifyColumnArgs {
3394
3390
Column : newCol ,
@@ -4645,11 +4641,10 @@ func (e *executor) CreatePrimaryKey(ctx sessionctx.Context, ti ast.Ident, indexN
4645
4641
OpType : model .OpAddIndex ,
4646
4642
}
4647
4643
4648
- reorgMeta , err := newReorgMetaFromVariables (job , ctx )
4644
+ err = initJobReorgMetaFromVariables (job , ctx )
4649
4645
if err != nil {
4650
4646
return err
4651
4647
}
4652
- job .ReorgMeta = reorgMeta
4653
4648
4654
4649
err = e .doDDLJob2 (ctx , job , args )
4655
4650
return errors .Trace (err )
@@ -4758,10 +4753,7 @@ func (e *executor) createVectorIndex(ctx sessionctx.Context, ti ast.Ident, index
4758
4753
return errors .Trace (err )
4759
4754
}
4760
4755
4761
- job , err := buildAddIndexJobWithoutTypeAndArgs (ctx , schema , t )
4762
- if err != nil {
4763
- return errors .Trace (err )
4764
- }
4756
+ job := buildAddIndexJobWithoutTypeAndArgs (ctx , schema , t )
4765
4757
job .Version = model .GetJobVerInUse ()
4766
4758
job .Type = model .ActionAddVectorIndex
4767
4759
indexPartSpecifications [0 ].Expr = nil
@@ -4788,32 +4780,20 @@ func (e *executor) createVectorIndex(ctx sessionctx.Context, ti ast.Ident, index
4788
4780
return errors .Trace (err )
4789
4781
}
4790
4782
4791
- func buildAddIndexJobWithoutTypeAndArgs (ctx sessionctx.Context , schema * model.DBInfo , t table.Table ) (* model.Job , error ) {
4792
- tzName , tzOffset := ddlutil .GetTimeZone (ctx )
4783
+ func buildAddIndexJobWithoutTypeAndArgs (ctx sessionctx.Context , schema * model.DBInfo , t table.Table ) * model.Job {
4793
4784
charset , collate := ctx .GetSessionVars ().GetCharsetInfo ()
4794
4785
job := & model.Job {
4795
4786
SchemaID : schema .ID ,
4796
4787
TableID : t .Meta ().ID ,
4797
4788
SchemaName : schema .Name .L ,
4798
4789
TableName : t .Meta ().Name .L ,
4799
4790
BinlogInfo : & model.HistoryInfo {},
4800
- ReorgMeta : & model.DDLReorgMeta {
4801
- SQLMode : ctx .GetSessionVars ().SQLMode ,
4802
- Warnings : make (map [errors.ErrorID ]* terror.Error ),
4803
- WarningsCount : make (map [errors.ErrorID ]int64 ),
4804
- Location : & model.TimeZoneLocation {Name : tzName , Offset : tzOffset },
4805
- },
4806
- Priority : ctx .GetSessionVars ().DDLReorgPriority ,
4807
- Charset : charset ,
4808
- Collate : collate ,
4809
- SQLMode : ctx .GetSessionVars ().SQLMode ,
4791
+ Priority : ctx .GetSessionVars ().DDLReorgPriority ,
4792
+ Charset : charset ,
4793
+ Collate : collate ,
4794
+ SQLMode : ctx .GetSessionVars ().SQLMode ,
4810
4795
}
4811
- reorgMeta , err := newReorgMetaFromVariables (job , ctx )
4812
- if err != nil {
4813
- return nil , errors .Trace (err )
4814
- }
4815
- job .ReorgMeta = reorgMeta
4816
- return job , nil
4796
+ return job
4817
4797
}
4818
4798
4819
4799
func (e * executor ) CreateIndex (ctx sessionctx.Context , stmt * ast.CreateIndexStmt ) error {
@@ -4907,15 +4887,17 @@ func (e *executor) createIndex(ctx sessionctx.Context, ti ast.Ident, keyType ast
4907
4887
// global is set to 'false' is just there to be backwards compatible,
4908
4888
// to avoid unmarshal issues, it is now part of indexOption.
4909
4889
global := false
4910
- job , err := buildAddIndexJobWithoutTypeAndArgs (ctx , schema , t )
4911
- if err != nil {
4912
- return errors .Trace (err )
4913
- }
4890
+ job := buildAddIndexJobWithoutTypeAndArgs (ctx , schema , t )
4914
4891
4915
4892
job .Version = model .GetJobVerInUse ()
4916
4893
job .Type = model .ActionAddIndex
4917
4894
job .CDCWriteSource = ctx .GetSessionVars ().CDCWriteSource
4918
4895
4896
+ err = initJobReorgMetaFromVariables (job , ctx )
4897
+ if err != nil {
4898
+ return errors .Trace (err )
4899
+ }
4900
+
4919
4901
args := & model.ModifyIndexArgs {
4920
4902
IndexArgs : []* model.IndexArg {{
4921
4903
Unique : unique ,
@@ -4937,44 +4919,80 @@ func (e *executor) createIndex(ctx sessionctx.Context, ti ast.Ident, keyType ast
4937
4919
return errors .Trace (err )
4938
4920
}
4939
4921
4940
- func newReorgMetaFromVariables (job * model.Job , sctx sessionctx.Context ) (* model.DDLReorgMeta , error ) {
4941
- reorgMeta := NewDDLReorgMeta (sctx )
4942
- reorgMeta .IsDistReorg = variable .EnableDistTask .Load ()
4943
- reorgMeta .IsFastReorg = variable .EnableFastReorg .Load ()
4944
- reorgMeta .TargetScope = variable .ServiceScope .Load ()
4945
- if sv , ok := sctx .GetSessionVars ().GetSystemVar (variable .TiDBDDLReorgWorkerCount ); ok {
4946
- reorgMeta .Concurrency = variable .TidbOptInt (sv , 0 )
4922
+ func initJobReorgMetaFromVariables (job * model.Job , sctx sessionctx.Context ) error {
4923
+ m := NewDDLReorgMeta (sctx )
4924
+ setReorgParam := func () {
4925
+ if sv , ok := sctx .GetSessionVars ().GetSystemVar (variable .TiDBDDLReorgWorkerCount ); ok {
4926
+ m .Concurrency = variable .TidbOptInt (sv , 0 )
4927
+ }
4928
+ if sv , ok := sctx .GetSessionVars ().GetSystemVar (variable .TiDBDDLReorgBatchSize ); ok {
4929
+ m .BatchSize = variable .TidbOptInt (sv , 0 )
4930
+ }
4947
4931
}
4948
- if sv , ok := sctx .GetSessionVars ().GetSystemVar (variable .TiDBDDLReorgBatchSize ); ok {
4949
- reorgMeta .BatchSize = variable .TidbOptInt (sv , 0 )
4932
+ setDistTaskParam := func () error {
4933
+ m .IsDistReorg = variable .EnableDistTask .Load ()
4934
+ m .IsFastReorg = variable .EnableFastReorg .Load ()
4935
+ m .TargetScope = variable .ServiceScope .Load ()
4936
+ if hasSysDB (job ) {
4937
+ if m .IsDistReorg {
4938
+ logutil .DDLLogger ().Info ("cannot use distributed task execution on system DB" ,
4939
+ zap .Stringer ("job" , job ))
4940
+ }
4941
+ m .IsDistReorg = false
4942
+ m .IsFastReorg = false
4943
+ failpoint .Inject ("reorgMetaRecordFastReorgDisabled" , func (_ failpoint.Value ) {
4944
+ LastReorgMetaFastReorgDisabled = true
4945
+ })
4946
+ }
4947
+ if m .IsDistReorg && ! m .IsFastReorg {
4948
+ return dbterror .ErrUnsupportedDistTask
4949
+ }
4950
+ return nil
4950
4951
}
4951
4952
4952
- if reorgMeta .IsDistReorg && ! reorgMeta .IsFastReorg {
4953
- return nil , dbterror .ErrUnsupportedDistTask
4954
- }
4955
- if hasSysDB (job ) {
4956
- if reorgMeta .IsDistReorg {
4957
- logutil .DDLLogger ().Info ("cannot use distributed task execution on system DB" ,
4958
- zap .Stringer ("job" , job ))
4953
+ switch job .Type {
4954
+ case model .ActionAddIndex , model .ActionAddPrimaryKey :
4955
+ setReorgParam ()
4956
+ err := setDistTaskParam ()
4957
+ if err != nil {
4958
+ return err
4959
4959
}
4960
- reorgMeta .IsDistReorg = false
4961
- reorgMeta .IsFastReorg = false
4962
- failpoint .Inject ("reorgMetaRecordFastReorgDisabled" , func (_ failpoint.Value ) {
4963
- LastReorgMetaFastReorgDisabled = true
4964
- })
4960
+ case model .ActionReorganizePartition ,
4961
+ model .ActionRemovePartitioning ,
4962
+ model .ActionAlterTablePartitioning ,
4963
+ model .ActionModifyColumn :
4964
+ setReorgParam ()
4965
+ case model .ActionMultiSchemaChange :
4966
+ for _ , sub := range job .MultiSchemaInfo .SubJobs {
4967
+ switch sub .Type {
4968
+ case model .ActionAddIndex , model .ActionAddPrimaryKey :
4969
+ setReorgParam ()
4970
+ err := setDistTaskParam ()
4971
+ if err != nil {
4972
+ return err
4973
+ }
4974
+ case model .ActionReorganizePartition ,
4975
+ model .ActionRemovePartitioning ,
4976
+ model .ActionAlterTablePartitioning ,
4977
+ model .ActionModifyColumn :
4978
+ setReorgParam ()
4979
+ }
4980
+ }
4981
+ default :
4982
+ return nil
4965
4983
}
4966
-
4984
+ job . ReorgMeta = m
4967
4985
logutil .DDLLogger ().Info ("initialize reorg meta" ,
4968
4986
zap .String ("jobSchema" , job .SchemaName ),
4969
4987
zap .String ("jobTable" , job .TableName ),
4970
4988
zap .Stringer ("jobType" , job .Type ),
4971
- zap .Bool ("enableDistTask" , reorgMeta .IsDistReorg ),
4972
- zap .Bool ("enableFastReorg" , reorgMeta .IsFastReorg ),
4973
- zap .String ("targetScope" , reorgMeta .TargetScope ),
4974
- zap .Int ("concurrency" , reorgMeta .Concurrency ),
4975
- zap .Int ("batchSize" , reorgMeta .BatchSize ),
4989
+ zap .Bool ("enableDistTask" , m .IsDistReorg ),
4990
+ zap .Bool ("enableFastReorg" , m .IsFastReorg ),
4991
+ zap .String ("targetScope" , m .TargetScope ),
4992
+ zap .Int ("concurrency" , m .Concurrency ),
4993
+ zap .Int ("batchSize" , m .BatchSize ),
4976
4994
)
4977
- return reorgMeta , nil
4995
+ return nil
4978
4996
}
4979
4997
4980
4998
// LastReorgMetaFastReorgDisabled is used for test.
0 commit comments