Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#54989
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
lance6716 authored and ti-chi-bot committed Jul 30, 2024
1 parent 31fb9de commit e71a14c
Show file tree
Hide file tree
Showing 2 changed files with 22 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 @@ -326,20 +326,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
}
15 changes: 15 additions & 0 deletions pkg/executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2375,5 +2375,20 @@ func runWithSystemSession(ctx context.Context, sctx sessionctx.Context, fn func(
return err
}
defer b.ReleaseSysSession(ctx, sysCtx)
<<<<<<< HEAD
=======

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
}
defer sysCtx.RollbackTxn(ctx)
if err = ResetContextOfStmt(sysCtx, &ast.SelectStmt{}); err != nil {
return err
}
>>>>>>> c5185cbdc58 (executor: `runWithSystemSession` also copy snapshot status (#54989))
return fn(sysCtx)
}

0 comments on commit e71a14c

Please sign in to comment.