diff --git a/br/pkg/gluetidb/glue.go b/br/pkg/gluetidb/glue.go index 2c8726310153b..3b3d71ef8cff6 100644 --- a/br/pkg/gluetidb/glue.go +++ b/br/pkg/gluetidb/glue.go @@ -206,18 +206,19 @@ func (gs *tidbSession) CreatePlacementPolicy(ctx context.Context, policy *model. // SplitBatchCreateTable provide a way to split batch into small batch when batch size is large than 6 MB. // The raft entry has limit size of 6 MB, a batch of CreateTables may hit this limitation // TODO: shall query string be set for each split batch create, it looks does not matter if we set once for all. -func (gs *tidbSession) SplitBatchCreateTable(schema model.CIStr, info []*model.TableInfo, l int, r int, cs ...ddl.CreateTableWithInfoConfigurier) error { +func (gs *tidbSession) SplitBatchCreateTable(schema model.CIStr, info []*model.TableInfo, cs ...ddl.CreateTableWithInfoConfigurier) error { var err error d := domain.GetDomain(gs.se).DDL() - if err = d.BatchCreateTableWithInfo(gs.se, schema, info[l:r], append(cs, ddl.OnExistIgnore)...); kv.ErrEntryTooLarge.Equal(err) { - if r-l == 1 { + if err = d.BatchCreateTableWithInfo(gs.se, schema, info, append(cs, ddl.OnExistIgnore)...); kv.ErrEntryTooLarge.Equal(err) { + if len(info) == 1 { return err } - err = gs.SplitBatchCreateTable(schema, info, l, (l+r)/2) + mid := len(info) / 2 + err = gs.SplitBatchCreateTable(schema, info[:mid]) if err != nil { return err } - err = gs.SplitBatchCreateTable(schema, info, (l+r)/2, r) + err = gs.SplitBatchCreateTable(schema, info[mid:]) if err != nil { return err } @@ -253,7 +254,7 @@ func (gs *tidbSession) CreateTables(ctx context.Context, tables map[string][]*mo cloneTables = append(cloneTables, table) } gs.se.SetValue(sessionctx.QueryString, queryBuilder.String()) - if err := gs.SplitBatchCreateTable(dbName, cloneTables, 0, len(cloneTables)); err != nil { + if err := gs.SplitBatchCreateTable(dbName, cloneTables); err != nil { //It is possible to failure when TiDB does not support model.ActionCreateTables. //In this circumstance, BatchCreateTableWithInfo returns errno.ErrInvalidDDLJob, //we fall back to old way that creating table one by one