Skip to content

Commit

Permalink
executor: only forbid setting tidb_snapshot in stale txn (pingcap#25794)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Jul 12, 2021
1 parent d4a17a6 commit c8bcc3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions executor/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ func (e *SetExecutor) setSysVariable(ctx context.Context, name string, v *expres
}
if sessionVars.InTxn() {
if name == variable.TxnIsolationOneShot ||
name == variable.TiDBTxnReadTS ||
name == variable.TiDBSnapshot {
name == variable.TiDBTxnReadTS {
return errors.Trace(ErrCantChangeTxCharacteristics)
}
if name == variable.TiDBSnapshot && sessionVars.TxnCtx.IsStaleness {
return errors.Trace(ErrCantChangeTxCharacteristics)
}
}
Expand Down
4 changes: 3 additions & 1 deletion executor/stale_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@ func (s *testStaleTxnSuite) TestStalenessAndHistoryRead(c *C) {
c.Assert(tk.Se.GetInfoSchema().SchemaMetaVersion(), Equals, schemaVer2)

// test snapshot mutex with txn
tk.MustExec("START TRANSACTION")
tk.MustExec(fmt.Sprintf(`START TRANSACTION READ ONLY AS OF TIMESTAMP '%s'`, time2.Format("2006-1-2 15:04:05.000")))
c.Assert(tk.Se.GetSessionVars().SnapshotTS, Equals, uint64(0))
c.Assert(tk.Se.GetSessionVars().TxnCtx.StartTS, Equals, time2TS)
c.Assert(tk.Se.GetSessionVars().SnapshotInfoschema, IsNil)
c.Assert(tk.Se.GetInfoSchema().SchemaMetaVersion(), Equals, schemaVer2)
err := tk.ExecToErr(`set @@tidb_snapshot="2020-10-08 16:45:26";`)
c.Assert(err, ErrorMatches, ".*Transaction characteristics can't be changed while a transaction is in progress")
c.Assert(tk.Se.GetSessionVars().SnapshotTS, Equals, uint64(0))
Expand Down

0 comments on commit c8bcc3b

Please sign in to comment.