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

Function TestPreCheckTableClusterIndex

br/pkg/task/restore_test.go:103–173  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

101}
102
103func TestPreCheckTableClusterIndex(t *testing.T) {
104 ctx := context.Background()
105 m, err := mock.NewCluster()
106 if err != nil {
107 panic(err)
108 }
109 err = m.Start()
110 if err != nil {
111 panic(err)
112 }
113 defer m.Stop()
114 g := gluetidb.New()
115 se, err := g.CreateSession(m.Storage)
116 require.NoError(t, err)
117
118 info, err := m.Domain.GetSnapshotInfoSchema(math.MaxUint64)
119 require.NoError(t, err)
120 dbSchema, isExist := info.SchemaByName(pmodel.NewCIStr("test"))
121 require.True(t, isExist)
122
123 tables := make([]*metautil.Table, 4)
124 intField := types.NewFieldType(mysql.TypeLong)
125 intField.SetCharset("binary")
126 for i := len(tables) - 1; i >= 0; i-- {
127 tables[i] = &metautil.Table{
128 DB: dbSchema,
129 Info: &model.TableInfo{
130 ID: int64(i),
131 Name: pmodel.NewCIStr("test" + strconv.Itoa(i)),
132 Columns: []*model.ColumnInfo{{
133 ID: 1,
134 Name: pmodel.NewCIStr("id"),
135 FieldType: *intField,
136 State: model.StatePublic,
137 }},
138 Charset: "utf8mb4",
139 Collate: "utf8mb4_bin",
140 },
141 }
142 err = se.CreateTable(ctx, tables[i].DB.Name, tables[i].Info, ddl.WithOnExist(ddl.OnExistIgnore))
143 require.NoError(t, err)
144 }
145
146 // exist different tables
147 tables[1].Info.IsCommonHandle = true
148 err = task.PreCheckTableClusterIndex(tables, nil, m.Domain)
149 require.Error(t, err)
150 require.Regexp(t, `.*@@tidb_enable_clustered_index should be ON \(backup table = true, created table = false\).*`, err.Error())
151
152 // exist different DDLs
153 jobs := []*model.Job{{
154 ID: 5,
155 Type: model.ActionCreateTable,
156 SchemaName: "test",
157 Query: "",
158 BinlogInfo: &model.HistoryInfo{
159 TableInfo: &model.TableInfo{
160 Name: pmodel.NewCIStr("test1"),

Callers

nothing calls this directly

Calls 13

StartMethod · 0.95
StopMethod · 0.95
SetCharsetMethod · 0.95
NewClusterFunction · 0.92
NewFunction · 0.92
NewFieldTypeFunction · 0.92
WithOnExistFunction · 0.92
GetSnapshotInfoSchemaMethod · 0.80
CreateSessionMethod · 0.65
SchemaByNameMethod · 0.65
CreateTableMethod · 0.65

Tested by

no test coverage detected