MCPcopy
hub / github.com/pingcap/tidb / CreateTables

Method CreateTables

br/pkg/restore/snap_client/client.go:1064–1090  ·  view source on GitHub ↗

CreateTables create tables, and generate their information. this function will use workers as the same number of sessionPool, leave sessionPool nil to send DDLs sequential.

(
	ctx context.Context,
	tables []*metautil.Table,
	newTS uint64,
)

Source from the content-addressed store, hash-verified

1062// this function will use workers as the same number of sessionPool,
1063// leave sessionPool nil to send DDLs sequential.
1064func (rc *SnapClient) CreateTables(
1065 ctx context.Context,
1066 tables []*metautil.Table,
1067 newTS uint64,
1068) ([]*restoreutils.CreatedTable, error) {
1069 log.Info("start create tables", zap.Int("total count", len(tables)))
1070 rc.generateRebasedTables(tables)
1071
1072 // try to restore tables in batch
1073 if rc.batchDdlSize > minBatchDdlSize && len(rc.dbPool) > 0 {
1074 tables, err := rc.createTablesBatch(ctx, tables, newTS)
1075 if err == nil {
1076 return tables, nil
1077 } else if !utils.FallBack2CreateTable(err) {
1078 return nil, errors.Trace(err)
1079 }
1080 // fall back to old create table (sequential create table)
1081 log.Info("fall back to the sequential create table")
1082 }
1083
1084 // restore tables in db pool
1085 if len(rc.dbPool) > 0 {
1086 return rc.createTablesSingle(ctx, rc.dbPool, tables, newTS)
1087 }
1088 // restore tables in one db
1089 return rc.createTablesSingle(ctx, []*tidallocdb.DB{rc.db}, tables, newTS)
1090}
1091
1092func (rc *SnapClient) createTables(
1093 ctx context.Context,

Callers 1

CreateTablesTestMethod · 0.95

Calls 4

generateRebasedTablesMethod · 0.95
createTablesBatchMethod · 0.95
createTablesSingleMethod · 0.95
FallBack2CreateTableFunction · 0.92

Tested by 1

CreateTablesTestMethod · 0.76