Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: remove infoschema.SchemaTables() API, replace it with SchemaTableInfos() #54664

Merged
merged 17 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions br/pkg/restore/log_client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,7 @@ func (rc *LogClient) InitSchemasReplaceForDDL(
info := rc.dom.InfoSchema()
shcemas := info.AllSchemaNames()
for _, schema := range shcemas {
for _, table := range info.SchemaTables(schema) {
tableInfo := table.Meta()
for _, tableInfo := range info.SchemaTableInfos(ctx, schema) {
if tableInfo.TiFlashReplica != nil && tableInfo.TiFlashReplica.Count > 0 {
return nil, errors.Errorf("exist table(s) have tiflash replica, please remove it before restore")
}
Expand Down
3 changes: 1 addition & 2 deletions br/pkg/task/restore_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ func resetTiFlashReplicas(ctx context.Context, g glue.Glue, storage kv.Storage,
expectTiFlashStoreCount := uint64(0)
needTiFlash := false
for _, s := range allSchemaName {
for _, t := range info.SchemaTables(s) {
t := t.Meta()
for _, t := range info.SchemaTableInfos(ctx, s) {
if t.TiFlashReplica != nil {
expectTiFlashStoreCount = max(expectTiFlashStoreCount, t.TiFlashReplica.Count)
recorder.AddTable(t.ID, *t.TiFlashReplica)
Expand Down
11 changes: 5 additions & 6 deletions pkg/ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (d *ddl) ModifySchemaSetTiFlashReplica(sctx sessionctx.Context, stmt *ast.A
return errors.Trace(dbterror.ErrUnsupportedTiFlashOperationForSysOrMemTable)
}

tbls := is.SchemaTables(dbInfo.Name)
tbls := is.SchemaTableInfos(context.Background(), dbInfo.Name)
total := len(tbls)
succ := 0
skip := 0
Expand All @@ -429,7 +429,6 @@ func (d *ddl) ModifySchemaSetTiFlashReplica(sctx sessionctx.Context, stmt *ast.A
threshold := uint32(sctx.GetSessionVars().BatchPendingTiFlashCount)

for _, tbl := range tbls {
tbl := tbl.Meta()
done, killed := isSessionDone(sctx)
if done {
logutil.DDLLogger().Info("abort batch add TiFlash replica", zap.Int64("schemaID", dbInfo.ID), zap.Uint32("isKilled", killed))
Expand Down Expand Up @@ -674,7 +673,7 @@ func (d *ddl) DropSchema(ctx sessionctx.Context, stmt *ast.DropDatabaseStmt) (er
return infoschema.ErrDatabaseDropExists.GenWithStackByArgs(stmt.Name)
}
fkCheck := ctx.GetSessionVars().ForeignKeyChecks
err = checkDatabaseHasForeignKeyReferred(is, old.Name, fkCheck)
err = checkDatabaseHasForeignKeyReferred(d.ctx, is, old.Name, fkCheck)
if err != nil {
return err
}
Expand Down Expand Up @@ -708,11 +707,11 @@ func (d *ddl) DropSchema(ctx sessionctx.Context, stmt *ast.DropDatabaseStmt) (er
return nil
}
// Clear table locks hold by the session.
tbs := is.SchemaTables(stmt.Name)
tbs := is.SchemaTableInfos(d.ctx, stmt.Name)
lockTableIDs := make([]int64, 0)
for _, tb := range tbs {
if ok, _ := ctx.CheckTableLocked(tb.Meta().ID); ok {
lockTableIDs = append(lockTableIDs, tb.Meta().ID)
if ok, _ := ctx.CheckTableLocked(tb.ID); ok {
lockTableIDs = append(lockTableIDs, tb.ID)
}
}
ctx.ReleaseTableLockByTableIDs(lockTableIDs)
Expand Down
12 changes: 6 additions & 6 deletions pkg/ddl/foreign_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,18 +601,18 @@ func (h *foreignKeyHelper) getTableFromStorage(is infoschema.InfoSchema, t *meta
return result, nil
}

func checkDatabaseHasForeignKeyReferred(is infoschema.InfoSchema, schema model.CIStr, fkCheck bool) error {
func checkDatabaseHasForeignKeyReferred(ctx context.Context, is infoschema.InfoSchema, schema model.CIStr, fkCheck bool) error {
if !fkCheck {
return nil
}
tables := is.SchemaTables(schema)
tables := is.SchemaTableInfos(ctx, schema)
tableNames := make([]ast.Ident, len(tables))
for i := range tables {
tableNames[i] = ast.Ident{Schema: schema, Name: tables[i].Meta().Name}
tableNames[i] = ast.Ident{Schema: schema, Name: tables[i].Name}
}
for _, tbl := range tables {
if referredFK := checkTableHasForeignKeyReferred(is, schema.L, tbl.Meta().Name.L, tableNames, fkCheck); referredFK != nil {
return errors.Trace(dbterror.ErrForeignKeyCannotDropParent.GenWithStackByArgs(tbl.Meta().Name, referredFK.ChildFKName, referredFK.ChildTable))
if referredFK := checkTableHasForeignKeyReferred(is, schema.L, tbl.Name.L, tableNames, fkCheck); referredFK != nil {
return errors.Trace(dbterror.ErrForeignKeyCannotDropParent.GenWithStackByArgs(tbl.Name, referredFK.ChildFKName, referredFK.ChildTable))
}
}
return nil
Expand All @@ -635,7 +635,7 @@ func checkDatabaseHasForeignKeyReferredInOwner(d *ddlCtx, t *meta.Meta, job *mod
if err != nil {
return errors.Trace(err)
}
err = checkDatabaseHasForeignKeyReferred(is, model.NewCIStr(job.SchemaName), fkCheck)
err = checkDatabaseHasForeignKeyReferred(d.ctx, is, model.NewCIStr(job.SchemaName), fkCheck)
if err != nil {
job.State = model.JobStateCancelled
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/ddl/placement_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ func CheckPlacementPolicyNotInUseFromInfoSchema(is infoschema.InfoSchema, policy
return dbterror.ErrPlacementPolicyInUse.GenWithStackByArgs(policy.Name)
}

for _, tbl := range is.SchemaTables(dbInfo.Name) {
tblInfo := tbl.Meta()
for _, tblInfo := range is.SchemaTableInfos(context.Background(), dbInfo.Name) {
if err := checkPlacementPolicyNotUsedByTable(tblInfo, policy); err != nil {
return err
}
Expand Down
Loading