@@ -2008,3 +2008,40 @@ func (s *testSessionSuite) TestDBUserNameLength(c *C) {
2008
2008
tk .MustExec (`grant all privileges on test.* to 'abcddfjakldfjaldddds'@'%' identified by ''` )
2009
2009
tk .MustExec (`grant all privileges on test.t to 'abcddfjakldfjaldddds'@'%' identified by ''` )
2010
2010
}
2011
+
2012
+ func (s * testSessionSuite ) TestDisableTxnAutoRetry (c * C ) {
2013
+ tk1 := testkit .NewTestKitWithInit (c , s .store )
2014
+ tk2 := testkit .NewTestKitWithInit (c , s .store )
2015
+ tk1 .MustExec ("create table no_retry (id int)" )
2016
+ tk1 .MustExec ("insert into no_retry values (1)" )
2017
+ tk1 .MustExec ("set @@tidb_disable_txn_auto_retry = 1" )
2018
+
2019
+ tk1 .MustExec ("begin" )
2020
+ tk1 .MustExec ("update no_retry set id = 2" )
2021
+
2022
+ tk2 .MustExec ("begin" )
2023
+ tk2 .MustExec ("update no_retry set id = 3" )
2024
+ tk2 .MustExec ("commit" )
2025
+
2026
+ // No auto retry because tidb_disable_txn_auto_retry is set to 1.
2027
+ _ , err := tk1 .Se .Execute (context .Background (), "commit" )
2028
+ c .Assert (err , NotNil )
2029
+
2030
+ // session 1 starts a transaction early.
2031
+ // execute a select statement to clear retry history.
2032
+ tk1 .MustExec ("select 1" )
2033
+ tk1 .Se .NewTxn ()
2034
+ // session 2 update the value.
2035
+ tk2 .MustExec ("update no_retry set id = 4" )
2036
+ // Autocommit update will retry, so it would not fail.
2037
+ tk1 .MustExec ("update no_retry set id = 5" )
2038
+
2039
+ // RestrictedSQL should retry.
2040
+ tk1 .Se .GetSessionVars ().InRestrictedSQL = true
2041
+ tk1 .MustExec ("begin" )
2042
+
2043
+ tk2 .MustExec ("update no_retry set id = 6" )
2044
+
2045
+ tk1 .MustExec ("update no_retry set id = 7" )
2046
+ tk1 .MustExec ("commit" )
2047
+ }
0 commit comments