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

session: if txn invalid do not active it and return an error #13935

Merged
merged 9 commits into from
Dec 9, 2019

Conversation

jackysp
Copy link
Member

@jackysp jackysp commented Dec 5, 2019

What problem does this PR solve?

If txn invalid, it is better to do not active it and return an error.

goroutine 102449 [running]:
github.com/pingcap/tidb/server.(*clientConn).Run.func1(0x23b8ce0, 0xc0011fd530, 0xc001312000)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/server/conn.go:612 +0xee
panic(0x1ebe500, 0x31c4a60)
    /usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/pingcap/tidb/executor.(*ExecStmt).Exec.func1(0xc000dca9e0, 0x23b8ce0, 0xc0011fd530, 0xc001020310)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/executor/adapter.go:229 +0x48c
panic(0x1ebe500, 0x31c4a60)
    /usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/pingcap/tidb/session.(*TxnState).SetOption(0xc001753d20, 0xb, 0x1e30c40, 0xc0017da190)
    <autogenerated>:1 +0x2e
github.com/pingcap/tidb/executor.UpdateForUpdateTS(0x23effa0, 0xc001753d10, 0x0, 0xc0013de600, 0x0)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/executor/adapter.go:488 +0xe5
github.com/pingcap/tidb/executor.(*ExecStmt).handlePessimisticLockError(0xc001020310, 0x23b8ce0, 0xc0011fd530, 0x23809e0, 0xc0013de600, 0x0, 0x0, 0x23809e0, 0xc0013de600)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/executor/adapter.go:524 +0xa23
github.com/pingcap/tidb/executor.(*ExecStmt).handlePessimisticDML(0xc001020310, 0x23b8ce0, 0xc0011fd530, 0x23bfa60, 0xc000358000, 0x355a9c0, 0xc0019e1f03)     /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/executor/adapter.go:449 +0x13c
github.com/pingcap/tidb/executor.(*ExecStmt).Exec(0xc001020310, 0x23b8ce0, 0xc0011fd530, 0x0, 0x0, 0x0, 0x0)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/executor/adapter.go:293 +0x3de
github.com/pingcap/tidb/session.runStmt(0x23b8ce0, 0xc0011fd530, 0x23effa0, 0xc001753d10, 0x23bf1e0, 0xc001020310, 0x0, 0x0, 0x0, 0x0)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/session/tidb.go:249 +0x1cb
github.com/pingcap/tidb/session.(*session).executeStatement(0xc001753d10, 0x23b8ce0, 0xc0011fd530, 0xfa, 0x23be2e0, 0xc0013de340, 0x23bf1e0, 0xc001020310, 0x0, 0x0, ...)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/session/session.go:976 +0x1ce
github.com/pingcap/tidb/session.(*session).execute(0xc001753d10, 0x23b8ce0, 0xc0011fd530, 0xc0019e1f01, 0x11, 0x0, 0xc00006c700, 0x7f20ccfb0b28, 0x0, 0xc000ad1500)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/session/session.go:1091 +0x96a
github.com/pingcap/tidb/session.(*session).Execute(0xc001753d10, 0x23b8ce0, 0xc0011fd530, 0xc0019e1f01, 0x11, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/session/session.go:1014 +0xdb
github.com/pingcap/tidb/server.(*TiDBContext).Execute(0xc0011fd980, 0x23b8ce0, 0xc0011fd530, 0xc0019e1f01, 0x11, 0xc42390, 0xc000b480f8, 0x8, 0x8, 0xc00181f4b8)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/server/driver_tidb.go:246 +0x7c
github.com/pingcap/tidb/server.(*clientConn).handleQuery(0xc001312000, 0x23b8ce0, 0xc0011fd530, 0xc0019e1f01, 0x11, 0x0, 0x0)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/server/conn.go:1195 +0x91
github.com/pingcap/tidb/server.(*clientConn).dispatch(0xc001312000, 0x23b8ce0, 0xc0011fd530, 0xc0019e1f01, 0x12, 0x12, 0x0, 0x0)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/server/conn.go:913 +0x5ea
github.com/pingcap/tidb/server.(*clientConn).Run(0xc001312000, 0x23b8ce0, 0xc0011fd530)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/server/conn.go:666 +0x276
github.com/pingcap/tidb/server.(*Server).onConn(0xc001303880, 0xc001312000)
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/server/server.go:440 +0x49f
created by github.com/pingcap/tidb/server.(*Server).Run
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/server/server.go:357 +0x831
"] [stack="github.com/pingcap/tidb/server.(*clientConn).Run.func1
    /home/jenkins/agent/workspace/tidb_release-3.0/go/src/github.com/pingcap/tidb/server/conn.go:614
runtime.gopanic

What is changed and how it works?

We should obey some rules,
if session.Txn(true), the txn should always be valid otherwise return an error for it.
if session.Txn(false), maybe we do not need to active the txn or it is close due to the lazy execute select statement, we should always check the txn is valid or not.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Related changes

  • Need to cherry-pick to the release branch

Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
@jackysp jackysp added type/bugfix This PR fixes a bug. component/session labels Dec 5, 2019
@jackysp
Copy link
Member Author

jackysp commented Dec 5, 2019

/run-all-tests

Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
@codecov
Copy link

codecov bot commented Dec 5, 2019

Codecov Report

Merging #13935 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #13935   +/-   ##
===========================================
  Coverage   80.3329%   80.3329%           
===========================================
  Files           480        480           
  Lines        121035     121035           
===========================================
  Hits          97231      97231           
  Misses        16086      16086           
  Partials       7718       7718

@jackysp
Copy link
Member Author

jackysp commented Dec 5, 2019

/run-all-tests

@jackysp
Copy link
Member Author

jackysp commented Dec 6, 2019

before:
企业微信截图_20191206110553

after:
企业微信截图_20191206110609

@jackysp jackysp requested a review from cfzjywxk December 6, 2019 03:30
@@ -82,7 +82,7 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error {
return err
}

txn, err := e.ctx.Txn(true)
txn, err := e.ctx.Txn(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check all these Txn(true) usages, seems many

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked all of them. In another way, if Txn(true), it prefers to return an error when txn is invalid, but all the tests passed.

executor/simple.go Outdated Show resolved Hide resolved
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
@coocood
Copy link
Member

coocood commented Dec 6, 2019

LGTM

@jackysp
Copy link
Member Author

jackysp commented Dec 9, 2019

PTAL @cfzjywxk @lysu @tiancaiamao

@cfzjywxk
Copy link
Contributor

cfzjywxk commented Dec 9, 2019

LGTM

1 similar comment
@tiancaiamao
Copy link
Contributor

LGTM

@tiancaiamao tiancaiamao added the status/LGT3 The PR has already had 3 LGTM. label Dec 9, 2019
@tiancaiamao tiancaiamao added the status/can-merge Indicates a PR has been approved by a committer. label Dec 9, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Dec 9, 2019

/run-all-tests

@sre-bot sre-bot merged commit 94481e8 into pingcap:master Dec 9, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Dec 9, 2019

cherry pick to release-3.0 failed

jackysp added a commit to jackysp/tidb that referenced this pull request Dec 9, 2019
…#13935)

 Conflicts:
	executor/batch_point_get.go
	executor/point_get.go
XiaTianliang pushed a commit to XiaTianliang/tidb that referenced this pull request Dec 21, 2019
imtbkcat pushed a commit to imtbkcat/tidb that referenced this pull request Jan 16, 2020
imtbkcat pushed a commit to imtbkcat/tidb that referenced this pull request Jan 16, 2020
@imtbkcat imtbkcat mentioned this pull request Jan 16, 2020
@jackysp jackysp deleted the pess_panic branch February 27, 2020 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/session status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants