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
session: do not keep history when the transaction retry is disabled #11192
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f5bf016
session: do not keep history when disable retry
jackysp 95cc7b4
Merge branch 'master' into no_hist
lonng 36ff466
address comments
jackysp c157539
Merge branch 'no_hist' of github.com:jackysp/tidb into no_hist
jackysp cb06095
address comments
jackysp 2a15b4c
address comments
jackysp fd672ba
address comments
jackysp 860144b
Merge branch 'master' into no_hist
coocood File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -545,7 +545,7 @@ func (s *testSessionSuite) TestRetryCleanTxn(c *C) { | |
c.Assert(err, IsNil) | ||
stmt, _ := session.Compile(context.TODO(), tk.Se, stmtNode) | ||
executor.ResetContextOfStmt(tk.Se, stmtNode) | ||
history.Add(0, stmt, tk.Se.GetSessionVars().StmtCtx) | ||
history.Add(stmt, tk.Se.GetSessionVars().StmtCtx) | ||
_, err = tk.Exec("commit") | ||
c.Assert(err, NotNil) | ||
txn, err := tk.Se.Txn(false) | ||
|
@@ -559,6 +559,7 @@ func (s *testSessionSuite) TestReadOnlyNotInHistory(c *C) { | |
tk.MustExec("create table history (a int)") | ||
tk.MustExec("insert history values (1), (2), (3)") | ||
tk.MustExec("set @@autocommit = 0") | ||
tk.MustExec("set tidb_disable_txn_auto_retry = 0") | ||
tk.MustQuery("select * from history") | ||
history := session.GetHistory(tk.Se) | ||
c.Assert(history.Count(), Equals, 0) | ||
|
@@ -572,6 +573,76 @@ func (s *testSessionSuite) TestReadOnlyNotInHistory(c *C) { | |
c.Assert(history.Count(), Equals, 0) | ||
} | ||
|
||
func (s *testSessionSuite) TestNoHistoryWhenDisableRetry(c *C) { | ||
tk := testkit.NewTestKitWithInit(c, s.store) | ||
tk.MustExec("create table history (a int)") | ||
tk.MustExec("set @@autocommit = 0") | ||
|
||
// retry_limit = 0 will not add history. | ||
tk.MustExec("set @@tidb_retry_limit = 0") | ||
tk.MustExec("insert history values (1)") | ||
c.Assert(session.GetHistory(tk.Se).Count(), Equals, 0) | ||
|
||
// Disable auto_retry will add history for auto committed only | ||
tk.MustExec("set @@autocommit = 1") | ||
tk.MustExec("set @@tidb_retry_limit = 10") | ||
tk.MustExec("set @@tidb_disable_txn_auto_retry = 1") | ||
c.Assert(failpoint.Enable("github.com/pingcap/tidb/session/keepHistory", `1*return(true)->return(false)`), IsNil) | ||
tk.MustExec("insert history values (1)") | ||
c.Assert(session.GetHistory(tk.Se).Count(), Equals, 1) | ||
c.Assert(failpoint.Disable("github.com/pingcap/tidb/session/keepHistory"), IsNil) | ||
tk.MustExec("begin") | ||
tk.MustExec("insert history values (1)") | ||
c.Assert(session.GetHistory(tk.Se).Count(), Equals, 0) | ||
tk.MustExec("commit") | ||
|
||
// Enable auto_retry will add history for both. | ||
tk.MustExec("set @@tidb_disable_txn_auto_retry = 0") | ||
c.Assert(failpoint.Enable("github.com/pingcap/tidb/session/keepHistory", `1*return(true)->return(false)`), IsNil) | ||
tk.MustExec("insert history values (1)") | ||
c.Assert(failpoint.Disable("github.com/pingcap/tidb/session/keepHistory"), IsNil) | ||
c.Assert(session.GetHistory(tk.Se).Count(), Equals, 1) | ||
tk.MustExec("begin") | ||
tk.MustExec("insert history values (1)") | ||
c.Assert(session.GetHistory(tk.Se).Count(), Equals, 2) | ||
tk.MustExec("commit") | ||
} | ||
|
||
func (s *testSessionSuite) TestNoRetryForCurrentTxn(c *C) { | ||
tk := testkit.NewTestKitWithInit(c, s.store) | ||
tk1 := testkit.NewTestKitWithInit(c, s.store) | ||
tk.MustExec("create table history (a int)") | ||
tk.MustExec("insert history values (1)") | ||
|
||
// Firstly, disable retry. | ||
tk.MustExec("set tidb_disable_txn_auto_retry = 1") | ||
tk.MustExec("begin") | ||
tk.MustExec("update history set a = 2") | ||
// Enable retry now | ||
tk.MustExec("set tidb_disable_txn_auto_retry = 0") | ||
|
||
tk1.MustExec("update history set a = 3") | ||
c.Assert(tk.ExecToErr("commit"), NotNil) | ||
} | ||
|
||
func (s *testSessionSuite) TestRetryForCurrentTxn(c *C) { | ||
tk := testkit.NewTestKitWithInit(c, s.store) | ||
tk1 := testkit.NewTestKitWithInit(c, s.store) | ||
tk.MustExec("create table history (a int)") | ||
tk.MustExec("insert history values (1)") | ||
|
||
// Firstly, disable retry. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Firstly enable retry? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
tk.MustExec("set tidb_disable_txn_auto_retry = 0") | ||
tk.MustExec("begin") | ||
tk.MustExec("update history set a = 2") | ||
// Enable retry now | ||
tk.MustExec("set tidb_disable_txn_auto_retry = 1") | ||
|
||
tk1.MustExec("update history set a = 3") | ||
tk.MustExec("commit") | ||
tk.MustQuery("select * from history").Check(testkit.Rows("2")) | ||
} | ||
|
||
// TestTruncateAlloc tests that the auto_increment ID does not reuse the old table's allocator. | ||
func (s *testSessionSuite) TestTruncateAlloc(c *C) { | ||
tk := testkit.NewTestKitWithInit(c, s.store) | ||
|
@@ -990,6 +1061,7 @@ func (s *testSessionSuite) TestBinaryReadOnly(c *C) { | |
id2, _, _, err := tk.Se.PrepareStmt("insert into t values (?)") | ||
c.Assert(err, IsNil) | ||
tk.MustExec("set autocommit = 0") | ||
tk.MustExec("set tidb_disable_txn_auto_retry = 0") | ||
_, err = tk.Se.ExecutePreparedStmt(context.Background(), id, []types.Datum{types.NewDatum(1)}) | ||
c.Assert(err, IsNil) | ||
c.Assert(session.GetHistory(tk.Se).Count(), Equals, 0) | ||
|
@@ -2177,6 +2249,7 @@ func (s *testSessionSuite) TestStatementCountLimit(c *C) { | |
defer func() { | ||
config.GetGlobalConfig().Performance.StmtCountLimit = saved | ||
}() | ||
tk.MustExec("set tidb_disable_txn_auto_retry = 0") | ||
tk.MustExec("begin") | ||
tk.MustExec("insert into stmt_count_limit values (1)") | ||
tk.MustExec("insert into stmt_count_limit values (2)") | ||
|
@@ -2195,6 +2268,7 @@ func (s *testSessionSuite) TestStatementCountLimit(c *C) { | |
func (s *testSessionSuite) TestBatchCommit(c *C) { | ||
tk := testkit.NewTestKitWithInit(c, s.store) | ||
tk.MustExec("set tidb_batch_commit = 1") | ||
tk.MustExec("set tidb_disable_txn_auto_retry = 0") | ||
tk.MustExec("create table t (id int)") | ||
saved := config.GetGlobalConfig().Performance | ||
config.GetGlobalConfig().Performance.StmtCountLimit = 3 | ||
|
@@ -2440,7 +2514,7 @@ func (s *testSchemaSuite) TestDisableTxnAutoRetry(c *C) { | |
// session 1 starts a transaction early. | ||
// execute a select statement to clear retry history. | ||
tk1.MustExec("select 1") | ||
tk1.Se.NewTxn(context.Background()) | ||
tk1.Se.PrepareTxnCtx(context.Background()) | ||
// session 2 update the value. | ||
tk2.MustExec("update no_retry set id = 4") | ||
// AutoCommit update will retry, so it would not fail. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done