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

ttl: fix ttl txn will not return error when rolling back (#39918) #39921

Merged
4 changes: 2 additions & 2 deletions ttl/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (s *session) RunInTxn(ctx context.Context, fn func() error) (err error) {
success := false
defer func() {
if !success {
_, err = s.ExecuteSQL(ctx, "ROLLBACK")
terror.Log(err)
_, rollbackErr := s.ExecuteSQL(ctx, "ROLLBACK")
terror.Log(rollbackErr)
}
}()

Expand Down
7 changes: 4 additions & 3 deletions ttl/session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ func TestSessionRunInTxn(t *testing.T) {
}))
tk2.MustQuery("select * from t order by id asc").Check(testkit.Rows("1 10"))

require.NoError(t, se.RunInTxn(context.TODO(), func() error {
err := se.RunInTxn(context.TODO(), func() error {
tk.MustExec("insert into t values (2, 20)")
return errors.New("err")
}))
return errors.New("mockErr")
})
require.EqualError(t, err, "mockErr")
tk2.MustQuery("select * from t order by id asc").Check(testkit.Rows("1 10"))

require.NoError(t, se.RunInTxn(context.TODO(), func() error {
Expand Down