@@ -1128,7 +1128,9 @@ func (e *executor) createTableWithInfoJob(
1128
1128
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
1129
1129
InvolvingSchemaInfo : involvingSchemas ,
1130
1130
SQLMode : ctx .GetSessionVars ().SQLMode ,
1131
+ SessionVars : make (map [string ]string ),
1131
1132
}
1133
+ job .AddSessionVars (vardef .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
1132
1134
args := & model.CreateTableArgs {
1133
1135
TableInfo : tbInfo ,
1134
1136
OnExistReplace : cfg .OnExist == OnExistReplace ,
@@ -1160,13 +1162,14 @@ func (e *executor) createTableWithInfoPost(
1160
1162
ctx sessionctx.Context ,
1161
1163
tbInfo * model.TableInfo ,
1162
1164
schemaID int64 ,
1165
+ scatterScope string ,
1163
1166
) error {
1164
1167
var err error
1165
1168
var partitions []model.PartitionDefinition
1166
1169
if pi := tbInfo .GetPartitionInfo (); pi != nil {
1167
1170
partitions = pi .Definitions
1168
1171
}
1169
- preSplitAndScatter (ctx , e .store , tbInfo , partitions )
1172
+ preSplitAndScatter (ctx , e .store , tbInfo , partitions , scatterScope )
1170
1173
if tbInfo .AutoIncID > 1 {
1171
1174
// Default tableAutoIncID base is 0.
1172
1175
// If the first ID is expected to greater than 1, we need to do rebase.
@@ -1221,7 +1224,11 @@ func (e *executor) CreateTableWithInfo(
1221
1224
err = nil
1222
1225
}
1223
1226
} else {
1224
- err = e .createTableWithInfoPost (ctx , tbInfo , jobW .SchemaID )
1227
+ var scatterScope string
1228
+ if val , ok := jobW .GetSessionVars (vardef .TiDBScatterRegion ); ok {
1229
+ scatterScope = val
1230
+ }
1231
+ err = e .createTableWithInfoPost (ctx , tbInfo , jobW .SchemaID , scatterScope )
1225
1232
}
1226
1233
1227
1234
return errors .Trace (err )
@@ -1245,7 +1252,9 @@ func (e *executor) BatchCreateTableWithInfo(ctx sessionctx.Context,
1245
1252
BinlogInfo : & model.HistoryInfo {},
1246
1253
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
1247
1254
SQLMode : ctx .GetSessionVars ().SQLMode ,
1255
+ SessionVars : make (map [string ]string ),
1248
1256
}
1257
+ job .AddSessionVars (vardef .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
1249
1258
1250
1259
var err error
1251
1260
@@ -1311,9 +1320,12 @@ func (e *executor) BatchCreateTableWithInfo(ctx sessionctx.Context,
1311
1320
}
1312
1321
return errors .Trace (err )
1313
1322
}
1314
-
1323
+ var scatterScope string
1324
+ if val , ok := jobW .GetSessionVars (vardef .TiDBScatterRegion ); ok {
1325
+ scatterScope = val
1326
+ }
1315
1327
for _ , tblArgs := range args .Tables {
1316
- if err = e .createTableWithInfoPost (ctx , tblArgs .TableInfo , jobW .SchemaID ); err != nil {
1328
+ if err = e .createTableWithInfoPost (ctx , tblArgs .TableInfo , jobW .SchemaID , scatterScope ); err != nil {
1317
1329
return errors .Trace (err )
1318
1330
}
1319
1331
}
@@ -1376,24 +1388,16 @@ func (e *executor) CreatePlacementPolicyWithInfo(ctx sessionctx.Context, policy
1376
1388
1377
1389
// preSplitAndScatter performs pre-split and scatter of the table's regions.
1378
1390
// If `pi` is not nil, will only split region for `pi`, this is used when add partition.
1379
- func preSplitAndScatter (ctx sessionctx.Context , store kv.Storage , tbInfo * model.TableInfo , parts []model.PartitionDefinition ) {
1391
+ func preSplitAndScatter (ctx sessionctx.Context , store kv.Storage , tbInfo * model.TableInfo , parts []model.PartitionDefinition , scatterScope string ) {
1392
+ failpoint .InjectCall ("preSplitAndScatter" , scatterScope )
1380
1393
if tbInfo .TempTableType != model .TempTableNone {
1381
1394
return
1382
1395
}
1383
1396
sp , ok := store .(kv.SplittableStore )
1384
1397
if ! ok || atomic .LoadUint32 (& EnableSplitTableRegion ) == 0 {
1385
1398
return
1386
1399
}
1387
- var (
1388
- preSplit func ()
1389
- scatterScope string
1390
- )
1391
- val , ok := ctx .GetSessionVars ().GetSystemVar (vardef .TiDBScatterRegion )
1392
- if ! ok {
1393
- logutil .DDLLogger ().Warn ("get system variable met problem, won't scatter region" )
1394
- } else {
1395
- scatterScope = val
1396
- }
1400
+ var preSplit func ()
1397
1401
if len (parts ) > 0 {
1398
1402
preSplit = func () { splitPartitionTableRegion (ctx , sp , tbInfo , parts , scatterScope ) }
1399
1403
} else {
@@ -2286,7 +2290,9 @@ func (e *executor) AddTablePartitions(ctx sessionctx.Context, ident ast.Ident, s
2286
2290
BinlogInfo : & model.HistoryInfo {},
2287
2291
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
2288
2292
SQLMode : ctx .GetSessionVars ().SQLMode ,
2293
+ SessionVars : make (map [string ]string ),
2289
2294
}
2295
+ job .AddSessionVars (vardef .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
2290
2296
args := & model.TablePartitionArgs {
2291
2297
PartInfo : partInfo ,
2292
2298
}
@@ -2797,7 +2803,9 @@ func (e *executor) TruncateTablePartition(ctx sessionctx.Context, ident ast.Iden
2797
2803
BinlogInfo : & model.HistoryInfo {},
2798
2804
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
2799
2805
SQLMode : ctx .GetSessionVars ().SQLMode ,
2806
+ SessionVars : make (map [string ]string ),
2800
2807
}
2808
+ job .AddSessionVars (vardef .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
2801
2809
args := & model.TruncateTableArgs {
2802
2810
OldPartitionIDs : pids ,
2803
2811
// job submitter will fill new partition IDs.
@@ -4299,7 +4307,9 @@ func (e *executor) TruncateTable(ctx sessionctx.Context, ti ast.Ident) error {
4299
4307
BinlogInfo : & model.HistoryInfo {},
4300
4308
CDCWriteSource : ctx .GetSessionVars ().CDCWriteSource ,
4301
4309
SQLMode : ctx .GetSessionVars ().SQLMode ,
4310
+ SessionVars : make (map [string ]string ),
4302
4311
}
4312
+ job .AddSessionVars (vardef .TiDBScatterRegion , getScatterScopeFromSessionctx (ctx ))
4303
4313
args := & model.TruncateTableArgs {
4304
4314
FKCheck : fkCheck ,
4305
4315
OldPartitionIDs : oldPartitionIDs ,
@@ -7080,3 +7090,14 @@ func (e *executor) RefreshMeta(sctx sessionctx.Context, args *model.RefreshMetaA
7080
7090
err := e .doDDLJob2 (sctx , job , args )
7081
7091
return errors .Trace (err )
7082
7092
}
7093
+
7094
+ func getScatterScopeFromSessionctx (sctx sessionctx.Context ) string {
7095
+ var scatterScope string
7096
+ val , ok := sctx .GetSessionVars ().GetSystemVar (vardef .TiDBScatterRegion )
7097
+ if ! ok {
7098
+ logutil .DDLLogger ().Info ("won't scatter region since system variable didn't set" )
7099
+ } else {
7100
+ scatterScope = val
7101
+ }
7102
+ return scatterScope
7103
+ }
0 commit comments