@@ -1117,7 +1117,9 @@ func (e *executor) createTableWithInfoJob(
1117
1117
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
1118
1118
InvolvingSchemaInfo : involvingSchemas ,
1119
1119
SQLMode : ctx .GetSessionVars ().SQLMode ,
1120
+ SessionVars : make (map [string ]string ),
1120
1121
}
1122
+ job .AddSessionVars (variable .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
1121
1123
args := & model.CreateTableArgs {
1122
1124
TableInfo : tbInfo ,
1123
1125
OnExistReplace : cfg .OnExist == OnExistReplace ,
@@ -1149,13 +1151,14 @@ func (e *executor) createTableWithInfoPost(
1149
1151
ctx sessionctx.Context ,
1150
1152
tbInfo * model.TableInfo ,
1151
1153
schemaID int64 ,
1154
+ scatterScope string ,
1152
1155
) error {
1153
1156
var err error
1154
1157
var partitions []model.PartitionDefinition
1155
1158
if pi := tbInfo .GetPartitionInfo (); pi != nil {
1156
1159
partitions = pi .Definitions
1157
1160
}
1158
- preSplitAndScatter (ctx , e .store , tbInfo , partitions )
1161
+ preSplitAndScatter (ctx , e .store , tbInfo , partitions , scatterScope )
1159
1162
if tbInfo .AutoIncID > 1 {
1160
1163
// Default tableAutoIncID base is 0.
1161
1164
// If the first ID is expected to greater than 1, we need to do rebase.
@@ -1210,7 +1213,11 @@ func (e *executor) CreateTableWithInfo(
1210
1213
err = nil
1211
1214
}
1212
1215
} 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 )
1214
1221
}
1215
1222
1216
1223
return errors .Trace (err )
@@ -1234,7 +1241,9 @@ func (e *executor) BatchCreateTableWithInfo(ctx sessionctx.Context,
1234
1241
BinlogInfo : & model.HistoryInfo {},
1235
1242
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
1236
1243
SQLMode : ctx .GetSessionVars ().SQLMode ,
1244
+ SessionVars : make (map [string ]string ),
1237
1245
}
1246
+ job .AddSessionVars (variable .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
1238
1247
1239
1248
var err error
1240
1249
@@ -1300,9 +1309,12 @@ func (e *executor) BatchCreateTableWithInfo(ctx sessionctx.Context,
1300
1309
}
1301
1310
return errors .Trace (err )
1302
1311
}
1303
-
1312
+ var scatterScope string
1313
+ if val , ok := jobW .GetSessionVars (variable .TiDBScatterRegion ); ok {
1314
+ scatterScope = val
1315
+ }
1304
1316
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 {
1306
1318
return errors .Trace (err )
1307
1319
}
1308
1320
}
@@ -1365,24 +1377,16 @@ func (e *executor) CreatePlacementPolicyWithInfo(ctx sessionctx.Context, policy
1365
1377
1366
1378
// preSplitAndScatter performs pre-split and scatter of the table's regions.
1367
1379
// 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 )
1369
1382
if tbInfo .TempTableType != model .TempTableNone {
1370
1383
return
1371
1384
}
1372
1385
sp , ok := store .(kv.SplittableStore )
1373
1386
if ! ok || atomic .LoadUint32 (& EnableSplitTableRegion ) == 0 {
1374
1387
return
1375
1388
}
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 ()
1386
1390
if len (parts ) > 0 {
1387
1391
preSplit = func () { splitPartitionTableRegion (ctx , sp , tbInfo , parts , scatterScope ) }
1388
1392
} else {
@@ -2275,7 +2279,9 @@ func (e *executor) AddTablePartitions(ctx sessionctx.Context, ident ast.Ident, s
2275
2279
BinlogInfo : & model.HistoryInfo {},
2276
2280
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
2277
2281
SQLMode : ctx .GetSessionVars ().SQLMode ,
2282
+ SessionVars : make (map [string ]string ),
2278
2283
}
2284
+ job .AddSessionVars (variable .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
2279
2285
args := & model.TablePartitionArgs {
2280
2286
PartInfo : partInfo ,
2281
2287
}
@@ -2786,7 +2792,9 @@ func (e *executor) TruncateTablePartition(ctx sessionctx.Context, ident ast.Iden
2786
2792
BinlogInfo : & model.HistoryInfo {},
2787
2793
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
2788
2794
SQLMode : ctx .GetSessionVars ().SQLMode ,
2795
+ SessionVars : make (map [string ]string ),
2789
2796
}
2797
+ job .AddSessionVars (variable .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
2790
2798
args := & model.TruncateTableArgs {
2791
2799
OldPartitionIDs : pids ,
2792
2800
// job submitter will fill new partition IDs.
@@ -4282,7 +4290,9 @@ func (e *executor) TruncateTable(ctx sessionctx.Context, ti ast.Ident) error {
4282
4290
BinlogInfo : & model.HistoryInfo {},
4283
4291
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
4284
4292
SQLMode : ctx .GetSessionVars ().SQLMode ,
4293
+ SessionVars : make (map [string ]string ),
4285
4294
}
4295
+ job .AddSessionVars (variable .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
4286
4296
args := & model.TruncateTableArgs {
4287
4297
FKCheck : fkCheck ,
4288
4298
OldPartitionIDs : oldPartitionIDs ,
@@ -6874,3 +6884,14 @@ func NewDDLReorgMeta(ctx sessionctx.Context) *model.DDLReorgMeta {
6874
6884
Version : model .CurrentReorgMetaVersion ,
6875
6885
}
6876
6886
}
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