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 Aug 26, 2024
1 parent e17bd5b commit 4ed49a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions executor/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,20 +300,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 executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,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 4ed49a0

Please sign in to comment.