Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: fix wrong resource tag of transaction commit statement (#25616) #25706

Merged
merged 4 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions server/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,15 @@ func (ts *tidbTestTopSQLSuite) TestTopSQLCPUProfile(c *C) {
}
}

// Test case 4: transaction commit
ctx4, cancel4 := context.WithCancel(context.Background())
defer cancel4()
go ts.loopExec(ctx4, c, func(db *sql.DB) {
db.Exec("begin")
db.Exec("insert into t () values (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),()")
db.Exec("commit")
})

// Check result of test case 1.
for _, ca := range cases1 {
checkFn(ca.sql, ca.planRegexp)
Expand All @@ -1396,6 +1405,9 @@ func (ts *tidbTestTopSQLSuite) TestTopSQLCPUProfile(c *C) {
checkFn(ca.prepare, ca.planRegexp)
ca.cancel()
}

// Check result of test case 4.
checkFn("commit", "")
}

func (ts *tidbTestTopSQLSuite) TestTopSQLAgent(c *C) {
Expand Down
16 changes: 9 additions & 7 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,11 @@ func (s *session) doCommit(ctx context.Context) error {
}
}

sessVars := s.GetSessionVars()
// Get the related table or partition IDs.
relatedPhysicalTables := s.GetSessionVars().TxnCtx.TableDeltaMap
relatedPhysicalTables := sessVars.TxnCtx.TableDeltaMap
// Get accessed global temporary tables in the transaction.
temporaryTables := s.GetSessionVars().TxnCtx.GlobalTemporaryTables
temporaryTables := sessVars.TxnCtx.GlobalTemporaryTables
physicalTableIDs := make([]int64, 0, len(relatedPhysicalTables))
for id := range relatedPhysicalTables {
// Schema change on global temporary tables doesn't affect transactions.
Expand All @@ -518,11 +519,12 @@ func (s *session) doCommit(ctx context.Context) error {
s.txn.SetOption(kv.SchemaChecker, domain.NewSchemaChecker(domain.GetDomain(s), s.GetInfoSchema().SchemaMetaVersion(), physicalTableIDs))
s.txn.SetOption(kv.InfoSchema, s.sessionVars.TxnCtx.InfoSchema)
s.txn.SetOption(kv.CommitHook, func(info string, _ error) { s.sessionVars.LastTxnInfo = info })
if s.GetSessionVars().EnableAmendPessimisticTxn {
if sessVars.EnableAmendPessimisticTxn {
s.txn.SetOption(kv.SchemaAmender, NewSchemaAmenderForTikvTxn(s))
}
s.txn.SetOption(kv.EnableAsyncCommit, s.GetSessionVars().EnableAsyncCommit)
s.txn.SetOption(kv.Enable1PC, s.GetSessionVars().Enable1PC)
s.txn.SetOption(kv.EnableAsyncCommit, sessVars.EnableAsyncCommit)
s.txn.SetOption(kv.Enable1PC, sessVars.Enable1PC)
s.txn.SetOption(kv.ResourceGroupTag, sessVars.StmtCtx.GetResourceGroupTag())
// priority of the sysvar is lower than `start transaction with causal consistency only`
if val := s.txn.GetOption(kv.GuaranteeLinearizability); val == nil || val.(bool) {
// We needn't ask the TiKV client to guarantee linearizability for auto-commit transactions
Expand All @@ -531,13 +533,13 @@ func (s *session) doCommit(ctx context.Context) error {
// An auto-commit transaction fetches its startTS from the TSO so its commitTS > its startTS > the commitTS
// of any previously committed transactions.
s.txn.SetOption(kv.GuaranteeLinearizability,
s.GetSessionVars().TxnCtx.IsExplicit && s.GetSessionVars().GuaranteeLinearizability)
sessVars.TxnCtx.IsExplicit && sessVars.GuaranteeLinearizability)
}
if tables := s.GetSessionVars().TxnCtx.GlobalTemporaryTables; len(tables) > 0 {
s.txn.SetOption(kv.KVFilter, temporaryTableKVFilter(tables))
}

return s.txn.Commit(tikvutil.SetSessionID(ctx, s.GetSessionVars().ConnectionID))
return s.txn.Commit(tikvutil.SetSessionID(ctx, sessVars.ConnectionID))
}

type temporaryTableKVFilter map[int64]tableutil.TempTable
Expand Down