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

Function PreCheckTableClusterIndex

br/pkg/task/restore.go:2306–2345  ·  view source on GitHub ↗

PreCheckTableClusterIndex checks whether backup tables and existed tables have different cluster index options。

(
	tables []*metautil.Table,
	ddlJobs []*model.Job,
	dom *domain.Domain,
)

Source from the content-addressed store, hash-verified

2304
2305// PreCheckTableClusterIndex checks whether backup tables and existed tables have different cluster index options。
2306func PreCheckTableClusterIndex(
2307 tables []*metautil.Table,
2308 ddlJobs []*model.Job,
2309 dom *domain.Domain,
2310) error {
2311 for _, table := range tables {
2312 oldTableInfo, err := restore.GetTableSchema(dom, table.DB.Name, table.Info.Name)
2313 // table exists in database
2314 if err == nil {
2315 if table.Info.IsCommonHandle != oldTableInfo.IsCommonHandle {
2316 log.Error("Clustered index option mismatch", zap.String("schemaName", table.DB.Name.O), zap.String("tableName", table.Info.Name.O))
2317 return errors.Annotatef(berrors.ErrRestoreModeMismatch,
2318 "Clustered index option mismatch. Restored cluster's @@tidb_enable_clustered_index should be %v (backup table = %v, created table = %v).",
2319 restore.TransferBoolToValue(table.Info.IsCommonHandle),
2320 table.Info.IsCommonHandle,
2321 oldTableInfo.IsCommonHandle)
2322 }
2323 }
2324 }
2325 for _, job := range ddlJobs {
2326 if job.Type == model.ActionCreateTable {
2327 tableInfo := job.BinlogInfo.TableInfo
2328 if tableInfo != nil {
2329 oldTableInfo, err := restore.GetTableSchema(dom, pmodel.NewCIStr(job.SchemaName), tableInfo.Name)
2330 // table exists in database
2331 if err == nil {
2332 if tableInfo.IsCommonHandle != oldTableInfo.IsCommonHandle {
2333 log.Error("Clustered index option mismatch", zap.String("schemaName", job.SchemaName), zap.String("tableName", tableInfo.Name.O))
2334 return errors.Annotatef(berrors.ErrRestoreModeMismatch,
2335 "Clustered index option mismatch. Restored cluster's @@tidb_enable_clustered_index should be %v (backup table = %v, created table = %v).",
2336 restore.TransferBoolToValue(tableInfo.IsCommonHandle),
2337 tableInfo.IsCommonHandle,
2338 oldTableInfo.IsCommonHandle)
2339 }
2340 }
2341 }
2342 }
2343 }
2344 return nil
2345}
2346
2347func getDatabases(tables []*metautil.Table) (dbs []*model.DBInfo) {
2348 dbIDs := make(map[int64]bool)

Callers 2

runSnapshotRestoreFunction · 0.85

Calls 4

GetTableSchemaFunction · 0.92
TransferBoolToValueFunction · 0.92
ErrorMethod · 0.65
StringMethod · 0.65

Tested by 1