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

*: activate txn for query on infoschema tables #57937

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
14 changes: 10 additions & 4 deletions pkg/executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,16 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex

// Cache the ret full rows in schemataRetriever
if !e.initialized {
is := sctx.GetInfoSchema().(infoschema.InfoSchema)
e.is = is

var err error
if sctx.GetSessionVars().InTxn() {
e.is, err = domain.GetDomain(sctx).GetSnapshotInfoSchema(sctx.GetSessionVars().TxnCtx.StartTS)
if err != nil {
return nil, errors.Trace(err)
}
} else {
e.is = sctx.GetInfoSchema().(infoschema.InfoSchema)
}

switch e.table.Name.O {
case infoschema.TableSchemata:
err = e.setDataFromSchemata(sctx)
Expand Down Expand Up @@ -177,7 +183,7 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex
infoschema.TableClientErrorsSummaryByHost:
err = e.setDataForClientErrorsSummary(sctx, e.table.Name.O)
case infoschema.TableAttributes:
err = e.setDataForAttributes(ctx, sctx, is)
err = e.setDataForAttributes(ctx, sctx, e.is)
case infoschema.TablePlacementPolicies:
err = e.setDataFromPlacementPolicies(sctx)
case infoschema.TableTrxSummary:
Expand Down
16 changes: 16 additions & 0 deletions pkg/executor/memtable_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ func (*MemTableReaderExec) isInspectionCacheableTable(tblName string) bool {
}
}

// Open implements the Executor Open interface.
func (e *MemTableReaderExec) Open(ctx context.Context) error {
err := e.BaseExecutor.Open(ctx)
if err != nil {
return errors.Trace(err)
}

// Activate the transaction, otherwise SELECT .. FROM INFORMATION_SCHEMA.XX .. does not block GC worker.
// And if the query last too long (10min), it causes error "GC life time is shorter than transaction duration"
if txn, err1 := e.Ctx().Txn(false); err1 == nil && txn != nil && txn.Valid() {
// Call e.Ctx().Txn(true) may panic, it's too difficult to debug all the callers.
_, err = e.Ctx().Txn(true)
}
return err
}

// Next implements the Executor Next interface.
func (e *MemTableReaderExec) Next(ctx context.Context, req *chunk.Chunk) error {
var (
Expand Down