Skip to content

Commit

Permalink
executor: runWithSystemSession also copy snapshot status (#54989) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jul 29, 2024
1 parent 033d247 commit d2304c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/executor/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,24 @@ func (e *SetExecutor) loadSnapshotInfoSchemaIfNeeded(name string, snapshotTS uin
if name != variable.TiDBSnapshot && name != variable.TiDBTxnReadTS {
return nil
}
vars := e.Ctx().GetSessionVars()
return loadSnapshotInfoSchemaIfNeeded(e.Ctx(), snapshotTS)
}

func loadSnapshotInfoSchemaIfNeeded(sctx sessionctx.Context, snapshotTS uint64) error {
vars := sctx.GetSessionVars()
if snapshotTS == 0 {
vars.SnapshotInfoschema = nil
return nil
}
logutil.BgLogger().Info("load snapshot info schema",
zap.Uint64("conn", vars.ConnectionID),
zap.Uint64("SnapshotTS", snapshotTS))
dom := domain.GetDomain(e.Ctx())
dom := domain.GetDomain(sctx)
snapInfo, err := dom.GetSnapshotInfoSchema(snapshotTS)
if err != nil {
return err
}

vars.SnapshotInfoschema = temptable.AttachLocalTemporaryTableInfoSchema(e.Ctx(), snapInfo)
vars.SnapshotInfoschema = temptable.AttachLocalTemporaryTableInfoSchema(sctx, snapInfo)
return nil
}
4 changes: 4 additions & 0 deletions pkg/executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,10 @@ func runWithSystemSession(ctx context.Context, sctx sessionctx.Context, fn func(
return err
}
defer b.ReleaseSysSession(ctx, sysCtx)

if err = loadSnapshotInfoSchemaIfNeeded(sysCtx, sctx.GetSessionVars().SnapshotTS); err != nil {
return err
}
// `fn` may use KV transaction, so initialize the txn here
if err = sessiontxn.NewTxn(ctx, sysCtx); err != nil {
return err
Expand Down

0 comments on commit d2304c8

Please sign in to comment.