Skip to content

Commit d2304c8

Browse files
authored
executor: runWithSystemSession also copy snapshot status (#54989) (#55028)
close #54964
1 parent 033d247 commit d2304c8

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pkg/executor/set.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,24 @@ func (e *SetExecutor) loadSnapshotInfoSchemaIfNeeded(name string, snapshotTS uin
316316
if name != variable.TiDBSnapshot && name != variable.TiDBTxnReadTS {
317317
return nil
318318
}
319-
vars := e.Ctx().GetSessionVars()
319+
return loadSnapshotInfoSchemaIfNeeded(e.Ctx(), snapshotTS)
320+
}
321+
322+
func loadSnapshotInfoSchemaIfNeeded(sctx sessionctx.Context, snapshotTS uint64) error {
323+
vars := sctx.GetSessionVars()
320324
if snapshotTS == 0 {
321325
vars.SnapshotInfoschema = nil
322326
return nil
323327
}
324328
logutil.BgLogger().Info("load snapshot info schema",
325329
zap.Uint64("conn", vars.ConnectionID),
326330
zap.Uint64("SnapshotTS", snapshotTS))
327-
dom := domain.GetDomain(e.Ctx())
331+
dom := domain.GetDomain(sctx)
328332
snapInfo, err := dom.GetSnapshotInfoSchema(snapshotTS)
329333
if err != nil {
330334
return err
331335
}
332336

333-
vars.SnapshotInfoschema = temptable.AttachLocalTemporaryTableInfoSchema(e.Ctx(), snapInfo)
337+
vars.SnapshotInfoschema = temptable.AttachLocalTemporaryTableInfoSchema(sctx, snapInfo)
334338
return nil
335339
}

pkg/executor/show.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,10 @@ func runWithSystemSession(ctx context.Context, sctx sessionctx.Context, fn func(
23982398
return err
23992399
}
24002400
defer b.ReleaseSysSession(ctx, sysCtx)
2401+
2402+
if err = loadSnapshotInfoSchemaIfNeeded(sysCtx, sctx.GetSessionVars().SnapshotTS); err != nil {
2403+
return err
2404+
}
24012405
// `fn` may use KV transaction, so initialize the txn here
24022406
if err = sessiontxn.NewTxn(ctx, sysCtx); err != nil {
24032407
return err

0 commit comments

Comments
 (0)