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

Method CreateTablesTest

br/pkg/restore/snap_client/export_test.go:85–115  ·  view source on GitHub ↗

CreateTables creates multiple tables, and returns their rewrite rules.

(
	dom *domain.Domain,
	tables []*metautil.Table,
	newTS uint64,
)

Source from the content-addressed store, hash-verified

83
84// CreateTables creates multiple tables, and returns their rewrite rules.
85func (rc *SnapClient) CreateTablesTest(
86 dom *domain.Domain,
87 tables []*metautil.Table,
88 newTS uint64,
89) (*restoreutils.RewriteRules, []*model.TableInfo, error) {
90 rc.dom = dom
91 rc.AllocTableIDs(context.TODO(), tables, false, false, nil)
92 rewriteRules := &restoreutils.RewriteRules{
93 Data: make([]*import_sstpb.RewriteRule, 0),
94 }
95 newTables := make([]*model.TableInfo, 0, len(tables))
96 tbMapping := map[string]int{}
97 for i, t := range tables {
98 tbMapping[t.Info.Name.String()] = i
99 }
100 rc.AllocTableIDs(context.Background(), tables, false, false, nil)
101 createdTables, err := rc.CreateTables(context.TODO(), tables, newTS)
102 if err != nil {
103 return nil, nil, err
104 }
105 for _, table := range createdTables {
106 rules := table.RewriteRule
107 rewriteRules.Data = append(rewriteRules.Data, rules.Data...)
108 newTables = append(newTables, table.Table)
109 }
110 // Let's ensure that it won't break the original order.
111 slices.SortFunc(newTables, func(i, j *model.TableInfo) int {
112 return cmp.Compare(tbMapping[i.Name.String()], tbMapping[j.Name.String()])
113 })
114 return rewriteRules, newTables, nil
115}
116
117func (rc *SnapClient) RegisterUpdateMetaAndLoadStats(
118 builder *PipelineConcurrentBuilder,

Callers 2

TestCreateTablesFunction · 0.80

Calls 4

AllocTableIDsMethod · 0.95
CreateTablesMethod · 0.95
StringMethod · 0.65
CompareMethod · 0.65

Tested by

no test coverage detected