@@ -1117,7 +1117,9 @@ func (e *executor) createTableWithInfoJob(
11171117 CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
11181118 InvolvingSchemaInfo : involvingSchemas ,
11191119 SQLMode : ctx .GetSessionVars ().SQLMode ,
1120+ SessionVars : make (map [string ]string ),
11201121 }
1122+ job .AddSessionVars (variable .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
11211123 args := & model.CreateTableArgs {
11221124 TableInfo : tbInfo ,
11231125 OnExistReplace : cfg .OnExist == OnExistReplace ,
@@ -1149,13 +1151,14 @@ func (e *executor) createTableWithInfoPost(
11491151 ctx sessionctx.Context ,
11501152 tbInfo * model.TableInfo ,
11511153 schemaID int64 ,
1154+ scatterScope string ,
11521155) error {
11531156 var err error
11541157 var partitions []model.PartitionDefinition
11551158 if pi := tbInfo .GetPartitionInfo (); pi != nil {
11561159 partitions = pi .Definitions
11571160 }
1158- preSplitAndScatter (ctx , e .store , tbInfo , partitions )
1161+ preSplitAndScatter (ctx , e .store , tbInfo , partitions , scatterScope )
11591162 if tbInfo .AutoIncID > 1 {
11601163 // Default tableAutoIncID base is 0.
11611164 // If the first ID is expected to greater than 1, we need to do rebase.
@@ -1210,7 +1213,11 @@ func (e *executor) CreateTableWithInfo(
12101213 err = nil
12111214 }
12121215 } else {
1213- err = e .createTableWithInfoPost (ctx , tbInfo , jobW .SchemaID )
1216+ var scatterScope string
1217+ if val , ok := jobW .GetSessionVars (variable .TiDBScatterRegion ); ok {
1218+ scatterScope = val
1219+ }
1220+ err = e .createTableWithInfoPost (ctx , tbInfo , jobW .SchemaID , scatterScope )
12141221 }
12151222
12161223 return errors .Trace (err )
@@ -1234,7 +1241,9 @@ func (e *executor) BatchCreateTableWithInfo(ctx sessionctx.Context,
12341241 BinlogInfo : & model.HistoryInfo {},
12351242 CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
12361243 SQLMode : ctx .GetSessionVars ().SQLMode ,
1244+ SessionVars : make (map [string ]string ),
12371245 }
1246+ job .AddSessionVars (variable .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
12381247
12391248 var err error
12401249
@@ -1300,9 +1309,12 @@ func (e *executor) BatchCreateTableWithInfo(ctx sessionctx.Context,
13001309 }
13011310 return errors .Trace (err )
13021311 }
1303-
1312+ var scatterScope string
1313+ if val , ok := jobW .GetSessionVars (variable .TiDBScatterRegion ); ok {
1314+ scatterScope = val
1315+ }
13041316 for _ , tblArgs := range args .Tables {
1305- if err = e .createTableWithInfoPost (ctx , tblArgs .TableInfo , jobW .SchemaID ); err != nil {
1317+ if err = e .createTableWithInfoPost (ctx , tblArgs .TableInfo , jobW .SchemaID , scatterScope ); err != nil {
13061318 return errors .Trace (err )
13071319 }
13081320 }
@@ -1365,24 +1377,16 @@ func (e *executor) CreatePlacementPolicyWithInfo(ctx sessionctx.Context, policy
13651377
13661378// preSplitAndScatter performs pre-split and scatter of the table's regions.
13671379// If `pi` is not nil, will only split region for `pi`, this is used when add partition.
1368- func preSplitAndScatter (ctx sessionctx.Context , store kv.Storage , tbInfo * model.TableInfo , parts []model.PartitionDefinition ) {
1380+ func preSplitAndScatter (ctx sessionctx.Context , store kv.Storage , tbInfo * model.TableInfo , parts []model.PartitionDefinition , scatterScope string ) {
1381+ failpoint .InjectCall ("preSplitAndScatter" , scatterScope )
13691382 if tbInfo .TempTableType != model .TempTableNone {
13701383 return
13711384 }
13721385 sp , ok := store .(kv.SplittableStore )
13731386 if ! ok || atomic .LoadUint32 (& EnableSplitTableRegion ) == 0 {
13741387 return
13751388 }
1376- var (
1377- preSplit func ()
1378- scatterScope string
1379- )
1380- val , ok := ctx .GetSessionVars ().GetSystemVar (variable .TiDBScatterRegion )
1381- if ! ok {
1382- logutil .DDLLogger ().Warn ("get system variable met problem, won't scatter region" )
1383- } else {
1384- scatterScope = val
1385- }
1389+ var preSplit func ()
13861390 if len (parts ) > 0 {
13871391 preSplit = func () { splitPartitionTableRegion (ctx , sp , tbInfo , parts , scatterScope ) }
13881392 } else {
@@ -2275,7 +2279,9 @@ func (e *executor) AddTablePartitions(ctx sessionctx.Context, ident ast.Ident, s
22752279 BinlogInfo : & model.HistoryInfo {},
22762280 CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
22772281 SQLMode : ctx .GetSessionVars ().SQLMode ,
2282+ SessionVars : make (map [string ]string ),
22782283 }
2284+ job .AddSessionVars (variable .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
22792285 args := & model.TablePartitionArgs {
22802286 PartInfo : partInfo ,
22812287 }
@@ -2786,7 +2792,9 @@ func (e *executor) TruncateTablePartition(ctx sessionctx.Context, ident ast.Iden
27862792 BinlogInfo : & model.HistoryInfo {},
27872793 CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
27882794 SQLMode : ctx .GetSessionVars ().SQLMode ,
2795+ SessionVars : make (map [string ]string ),
27892796 }
2797+ job .AddSessionVars (variable .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
27902798 args := & model.TruncateTableArgs {
27912799 OldPartitionIDs : pids ,
27922800 // job submitter will fill new partition IDs.
@@ -4282,7 +4290,9 @@ func (e *executor) TruncateTable(ctx sessionctx.Context, ti ast.Ident) error {
42824290 BinlogInfo : & model.HistoryInfo {},
42834291 CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
42844292 SQLMode : ctx .GetSessionVars ().SQLMode ,
4293+ SessionVars : make (map [string ]string ),
42854294 }
4295+ job .AddSessionVars (variable .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
42864296 args := & model.TruncateTableArgs {
42874297 FKCheck : fkCheck ,
42884298 OldPartitionIDs : oldPartitionIDs ,
@@ -6874,3 +6884,14 @@ func NewDDLReorgMeta(ctx sessionctx.Context) *model.DDLReorgMeta {
68746884 Version : model .CurrentReorgMetaVersion ,
68756885 }
68766886}
6887+
6888+ func getScatterScopeFromSessionctx (sctx sessionctx.Context ) string {
6889+ var scatterScope string
6890+ val , ok := sctx .GetSessionVars ().GetSystemVar (variable .TiDBScatterRegion )
6891+ if ! ok {
6892+ logutil .DDLLogger ().Info ("won't scatter region since system variable didn't set" )
6893+ } else {
6894+ scatterScope = val
6895+ }
6896+ return scatterScope
6897+ }
0 commit comments