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

*: add ctx parameter to infoschema TableByID #55329

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion br/pkg/restore/log_client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ func (rc *LogClient) FailpointDoChecksumForLogRestore(
reidRules[downstreamID] = upstreamID
}
for upstreamID, downstreamID := range idrules {
newTable, ok := infoSchema.TableByID(downstreamID)
newTable, ok := infoSchema.TableByID(ctx, downstreamID)
if !ok {
// a dropped table
continue
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/restore/tiflashrec/tiflash_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package tiflashrec

import (
"bytes"
"context"
"fmt"

"github.com/pingcap/log"
Expand Down Expand Up @@ -90,7 +91,7 @@ func (r *TiFlashRecorder) Rewrite(oldID int64, newID int64) {
func (r *TiFlashRecorder) GenerateResetAlterTableDDLs(info infoschema.InfoSchema) []string {
items := make([]string, 0, len(r.items))
r.Iterate(func(id int64, replica model.TiFlashReplicaInfo) {
table, ok := info.TableByID(id)
table, ok := info.TableByID(context.Background(), id)
if !ok {
log.Warn("Table do not exist, skipping", zap.Int64("id", id))
return
Expand Down Expand Up @@ -130,7 +131,7 @@ func (r *TiFlashRecorder) GenerateResetAlterTableDDLs(info infoschema.InfoSchema
func (r *TiFlashRecorder) GenerateAlterTableDDLs(info infoschema.InfoSchema) []string {
items := make([]string, 0, len(r.items))
r.Iterate(func(id int64, replica model.TiFlashReplicaInfo) {
table, ok := info.TableByID(id)
table, ok := info.TableByID(context.Background(), id)
if !ok {
log.Warn("Table do not exist, skipping", zap.Int64("id", id))
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddl/column_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestColumnAdd(t *testing.T) {
var jobID int64
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onJobUpdated", func(job *model.Job) {
jobID = job.ID
tbl, exist := dom.InfoSchema().TableByID(job.TableID)
tbl, exist := dom.InfoSchema().TableByID(context.Background(), job.TableID)
require.True(t, exist)
switch job.SchemaState {
case model.StateDeleteOnly:
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestColumnAdd(t *testing.T) {
first = true
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onJobUpdated", func(job *model.Job) {
jobID = job.ID
tbl, exist := dom.InfoSchema().TableByID(job.TableID)
tbl, exist := dom.InfoSchema().TableByID(context.Background(), job.TableID)
require.True(t, exist)
switch job.SchemaState {
case model.StateWriteOnly:
Expand Down
12 changes: 6 additions & 6 deletions pkg/ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func testCreateColumn(tk *testkit.TestKit, t *testing.T, ctx sessionctx.Context,
id := int64(idi)
v := getSchemaVer(t, ctx)
require.NoError(t, dom.Reload())
tblInfo, exist := dom.InfoSchema().TableByID(tblID)
tblInfo, exist := dom.InfoSchema().TableByID(context.Background(), tblID)
require.True(t, exist)
checkHistoryJobArgs(t, ctx, id, &historyJobArgs{ver: v, tbl: tblInfo.Meta()})
return id
Expand All @@ -74,7 +74,7 @@ func testCreateColumns(tk *testkit.TestKit, t *testing.T, ctx sessionctx.Context
id := int64(idi)
v := getSchemaVer(t, ctx)
require.NoError(t, dom.Reload())
tblInfo, exist := dom.InfoSchema().TableByID(tblID)
tblInfo, exist := dom.InfoSchema().TableByID(context.Background(), tblID)
require.True(t, exist)
checkHistoryJobArgs(t, ctx, id, &historyJobArgs{ver: v, tbl: tblInfo.Meta()})
return id
Expand All @@ -93,7 +93,7 @@ func testDropColumnInternal(tk *testkit.TestKit, t *testing.T, ctx sessionctx.Co
id := int64(idi)
v := getSchemaVer(t, ctx)
require.NoError(t, dom.Reload())
tblInfo, exist := dom.InfoSchema().TableByID(tblID)
tblInfo, exist := dom.InfoSchema().TableByID(context.Background(), tblID)
require.True(t, exist)
checkHistoryJobArgs(t, ctx, id, &historyJobArgs{ver: v, tbl: tblInfo.Meta()})
return id
Expand Down Expand Up @@ -124,7 +124,7 @@ func testCreateIndex(tk *testkit.TestKit, t *testing.T, ctx sessionctx.Context,
id := int64(idi)
v := getSchemaVer(t, ctx)
require.NoError(t, dom.Reload())
tblInfo, exist := dom.InfoSchema().TableByID(tblID)
tblInfo, exist := dom.InfoSchema().TableByID(context.Background(), tblID)
require.True(t, exist)
checkHistoryJobArgs(t, ctx, id, &historyJobArgs{ver: v, tbl: tblInfo.Meta()})
return id
Expand All @@ -149,7 +149,7 @@ func testDropColumns(tk *testkit.TestKit, t *testing.T, ctx sessionctx.Context,
id := int64(idi)
v := getSchemaVer(t, ctx)
require.NoError(t, dom.Reload())
tblInfo, exist := dom.InfoSchema().TableByID(tblID)
tblInfo, exist := dom.InfoSchema().TableByID(context.Background(), tblID)
require.True(t, exist)
checkHistoryJobArgs(t, ctx, id, &historyJobArgs{ver: v, tbl: tblInfo.Meta()})
return id
Expand Down Expand Up @@ -888,7 +888,7 @@ func TestDropColumns(t *testing.T) {

func testGetTable(t *testing.T, dom *domain.Domain, tableID int64) table.Table {
require.NoError(t, dom.Reload())
tbl, exist := dom.InfoSchema().TableByID(tableID)
tbl, exist := dom.InfoSchema().TableByID(context.Background(), tableID)
require.True(t, exist)
return tbl
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/db_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ func TestAddColumn2(t *testing.T) {
var writeOnlyTable table.Table
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onJobRunBefore", func(job *model.Job) {
if job.SchemaState == model.StateWriteOnly {
writeOnlyTable, _ = dom.InfoSchema().TableByID(job.TableID)
writeOnlyTable, _ = dom.InfoSchema().TableByID(context.Background(), job.TableID)
}
})
done := make(chan error, 1)
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddl/ddl_tiflash_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func PollAvailableTableProgress(schemas infoschema.InfoSchema, _ sessionctx.Cont
}
} else {
var ok bool
table, ok = schemas.TableByID(availableTableID.ID)
table, ok = schemas.TableByID(context.Background(), availableTableID.ID)
if !ok {
logutil.DDLLogger().Info("get table id failed, may be dropped or truncated",
zap.Int64("tableID", availableTableID.ID),
Expand Down Expand Up @@ -461,7 +461,7 @@ func (d *ddl) refreshTiFlashTicker(ctx sessionctx.Context, pollTiFlashContext *T
failpoint.Inject("waitForAddPartition", func(val failpoint.Value) {
for _, phyTable := range tableList {
is := d.infoCache.GetLatest()
_, ok := is.TableByID(phyTable.ID)
_, ok := is.TableByID(d.ctx, phyTable.ID)
if !ok {
tb, _, _ := is.FindTableByPartitionID(phyTable.ID)
if tb == nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/ddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3887,7 +3887,7 @@ func (e *executor) AlterTableDropStatistics(ctx sessionctx.Context, ident ast.Id
// UpdateTableReplicaInfo updates the table flash replica infos.
func (e *executor) UpdateTableReplicaInfo(ctx sessionctx.Context, physicalID int64, available bool) error {
is := e.infoCache.GetLatest()
tb, ok := is.TableByID(physicalID)
tb, ok := is.TableByID(e.ctx, physicalID)
if !ok {
tb, _, _ = is.FindTableByPartitionID(physicalID)
if tb == nil {
Expand Down Expand Up @@ -4303,7 +4303,7 @@ func (e *executor) renameTable(ctx sessionctx.Context, oldIdent, newIdent ast.Id
return nil
}

if tbl, ok := is.TableByID(tableID); ok {
if tbl, ok := is.TableByID(e.ctx, tableID); ok {
if tbl.Meta().TableCacheStatusType != model.TableCacheStatusDisable {
return errors.Trace(dbterror.ErrOptOnCacheTable.GenWithStackByArgs("Rename Table"))
}
Expand Down Expand Up @@ -4351,7 +4351,7 @@ func (e *executor) renameTables(ctx sessionctx.Context, oldIdents, newIdents []a
return err
}

if t, ok := is.TableByID(tableID); ok {
if t, ok := is.TableByID(e.ctx, tableID); ok {
if t.Meta().TableCacheStatusType != model.TableCacheStatusDisable {
return errors.Trace(dbterror.ErrOptOnCacheTable.GenWithStackByArgs("Rename Tables"))
}
Expand Down Expand Up @@ -5291,7 +5291,7 @@ func (e *executor) UnlockTables(ctx sessionctx.Context, unlockTables []model.Tab
if !ok {
continue
}
tbl, ok := is.TableByID(t.TableID)
tbl, ok := is.TableByID(e.ctx, t.TableID)
if !ok {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddl/index_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestIndexChange(t *testing.T) {
ctx1 := testNewContext(store)
prevState = job.SchemaState
require.NoError(t, dom.Reload())
tbl, exist := dom.InfoSchema().TableByID(job.TableID)
tbl, exist := dom.InfoSchema().TableByID(context.Background(), job.TableID)
require.True(t, exist)
switch job.SchemaState {
case model.StateDeleteOnly:
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestIndexChange(t *testing.T) {
prevState = job.SchemaState
var err error
require.NoError(t, dom.Reload())
tbl, exist := dom.InfoSchema().TableByID(job.TableID)
tbl, exist := dom.InfoSchema().TableByID(context.Background(), job.TableID)
require.True(t, exist)
ctx1 := testNewContext(store)
switch job.SchemaState {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/tests/fk/foreign_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ func getTableInfo(t *testing.T, dom *domain.Domain, db, tb string) *model.TableI
is := dom.InfoSchema()
tbl, err := is.TableByName(context.Background(), model.NewCIStr(db), model.NewCIStr(tb))
require.NoError(t, err)
_, exist := is.TableByID(tbl.Meta().ID)
_, exist := is.TableByID(context.Background(), tbl.Meta().ID)
require.True(t, exist)
return tbl.Meta()
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/domain/historical_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package domain

import (
"context"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
domain_metrics "github.com/pingcap/tidb/pkg/domain/metrics"
Expand Down Expand Up @@ -64,7 +66,7 @@ func (w *HistoricalStatsWorker) DumpHistoricalStats(tableID int64, statsHandle *
is := GetDomain(sctx).InfoSchema()
isPartition := false
var tblInfo *model.TableInfo
tbl, existed := is.TableByID(tableID)
tbl, existed := is.TableByID(context.Background(), tableID)
if !existed {
tbl, db, p := is.FindTableByPartitionID(tableID)
if !(tbl != nil && db != nil && p != nil) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func filterAndCollectTasks(tasks []*analyzeTask, statsHandle *handle.Handle, is
skippedTables = append(skippedTables, fmt.Sprintf("%s.%s partition (%s)", schema.Name, tbl.Meta().Name.O, def.Name.O))
}
} else {
tbl, ok := is.TableByID(physicalTableID)
tbl, ok := is.TableByID(context.Background(), physicalTableID)
if !ok {
logutil.BgLogger().Warn("Unknown table ID in analyze task", zap.Int64("tid", physicalTableID))
} else {
Expand Down
3 changes: 2 additions & 1 deletion pkg/executor/analyze_global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package executor

import (
"context"
"fmt"

"github.com/pingcap/tidb/pkg/domain"
Expand Down Expand Up @@ -93,7 +94,7 @@ func (e *AnalyzeExec) handleGlobalStats(statsHandle *handle.Handle, globalStatsM
func (e *AnalyzeExec) newAnalyzeHandleGlobalStatsJob(key globalStatsKey) *statistics.AnalyzeJob {
dom := domain.GetDomain(e.Ctx())
is := dom.InfoSchema()
table, ok := is.TableByID(key.tableID)
table, ok := is.TableByID(context.Background(), key.tableID)
if !ok {
return nil
}
Expand Down
Loading
Loading