Skip to content

Commit

Permalink
ttl: fix ttl txn will not return error when rolling back (#39918)
Browse files Browse the repository at this point in the history
close #39917
  • Loading branch information
lcwangchao authored Dec 14, 2022
1 parent 388e008 commit 66a2e96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ttl/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,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

0 comments on commit 66a2e96

Please sign in to comment.