tidb icon indicating copy to clipboard operation
tidb copied to clipboard

txn: add db name and table name in write conflict error message

Open ekexium opened this issue 3 years ago • 4 comments

Signed-off-by: ekexium [email protected]

What problem does this PR solve?

Issue Number: close #37257

Problem Summary:

What is changed and how it works?

The decoded row handle or index values are already there, so this PR adds db names and table names when possible.

Due to the limit of the current error handling framework (lack of structured info in a generated Error type), the implementation is dirty. It separates the key info into 4 parts in the error message. When TiDB is able to use infoschema to find the table, it parses the error message to find the table id and generate a new error.

Now a write conflict error message looks like

(9007, 'Write conflict, txnStartTS=436140757050982401, conflictStartTS=436140759711481857, conflictCommitTS=436140759711481858, key={tableID=70, tableName=test.t, handle=7} primary={tableID=70, tableName=test.t, handle=6}, reason=Optimistic [try again later]')

Check List

Tests

  • [x] Unit test
  • [ ] Integration test
  • [x] Manual test (add detailed scripts or steps below)
  • [ ] No code

Side effects

  • [ ] Performance regression: Consumes more CPU
  • [ ] Performance regression: Consumes more Memory
  • [ ] Breaking backward compatibility

Documentation

  • [ ] Affects user behaviors
  • [ ] Contains syntax changes
  • [ ] Contains variable changes
  • [ ] Contains experimental features
  • [ ] Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

ekexium avatar Sep 21 '22 07:09 ekexium

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • cfzjywxk
  • sticnarf

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment. After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review. Reviewer can cancel approval by submitting a request changes review.

ti-chi-bot avatar Sep 21 '22 07:09 ti-chi-bot

ErrWriteConflict error is used in so many places, but this PR replaces only the ErrWriteConflict in commit retry, is it ok ?

TonsnakeLin avatar Sep 21 '22 14:09 TonsnakeLin

ErrWriteConflict error is used in so many places, but this PR replaces only the ErrWriteConflict in commit retry, is it ok ?

I think it's on the critical path of returning a write conflict error to user. So I suppose it's enough. Did I miss anything?

ekexium avatar Sep 22 '22 04:09 ekexium

ErrWriteConflict error is used in so many places, but this PR replaces only the ErrWriteConflict in commit retry, is it ok ?

I think it's on the critical path of returning a write conflict error to user. So I suppose it's enough. Did I miss anything?

I worried about that if the sql statements execution meets a writeconfilict error and returns the error directly, but I can't find the case. when retry count is more than PessimisticTxn.MaxRetryCount, it returns the error made by errors.New("pessimistic lock retry limit reached but not ErrWriteConflict. So, I can't find what you missed.

TonsnakeLin avatar Sep 22 '22 05:09 TonsnakeLin

/run-check_dev

ekexium avatar Sep 26 '22 08:09 ekexium

/run-build /run-check-dev /run-check-dev2 /run-unit-test

wuhuizuo avatar Sep 26 '22 08:09 wuhuizuo

/run-check_dev /run-check_dev2

wuhuizuo avatar Sep 26 '22 09:09 wuhuizuo

/run-check_dev

wuhuizuo avatar Sep 26 '22 09:09 wuhuizuo

I can't find other problem, LGTM.

TonsnakeLin avatar Sep 26 '22 12:09 TonsnakeLin

@TonsnakeLin: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

ti-chi-bot avatar Sep 26 '22 12:09 ti-chi-bot

Will it work fine with a common handle?

sticnarf avatar Sep 27 '22 03:09 sticnarf

Will it work fine with a common handle?

It does. Though the decoded handle is not easy to interpret.

ekexium avatar Sep 27 '22 04:09 ekexium

/merge

cfzjywxk avatar Sep 27 '22 07:09 cfzjywxk

This pull request has been accepted and is ready to merge.

Commit hash: 5a9a3ca01bd05ce33a0b3b2517b0f49d0daad2aa

ti-chi-bot avatar Sep 27 '22 07:09 ti-chi-bot

@ekexium TestWriteConflictPrettyFormat fails because you add the key to the error.

sticnarf avatar Sep 28 '22 05:09 sticnarf

Oops

ekexium avatar Sep 28 '22 05:09 ekexium

/merge

sticnarf avatar Sep 28 '22 06:09 sticnarf

This pull request has been accepted and is ready to merge.

Commit hash: 3762b6fd64049ea2c430e38cabe1cc875aae6528

ti-chi-bot avatar Sep 28 '22 06:09 ti-chi-bot

/run-check-dev

wuhuizuo avatar Sep 28 '22 06:09 wuhuizuo

@ekexium Probably the CI failure is caused by your stale bazel file?

sticnarf avatar Sep 28 '22 07:09 sticnarf

/run-check_dev

ekexium avatar Sep 28 '22 07:09 ekexium

/run-check_dev /run-unit-test

ekexium avatar Sep 29 '22 06:09 ekexium

/run-build

ekexium avatar Oct 11 '22 08:10 ekexium

@sticnarf Could you help merge it?

ekexium avatar Oct 11 '22 08:10 ekexium

/merge

sticnarf avatar Oct 11 '22 08:10 sticnarf

This pull request has been accepted and is ready to merge.

Commit hash: f3d0ac15381a415d625036ca9206d91c2a8305a7

ti-chi-bot avatar Oct 11 '22 08:10 ti-chi-bot

TiDB MergeCI notify

✅ Well Done! New fixed [3] after this pr merged.

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-ddl-test ✅ all 6 tests passed 32 min Fixed
idc-jenkins-ci-tidb/integration-common-test ✅ all 17 tests passed 17 min Fixed
idc-jenkins-ci-tidb/integration-compatibility-test ✅ all 1 tests passed 3 min 5 sec Fixed
idc-jenkins-ci/integration-cdc-test 🟢 all 37 tests passed 28 min Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 12 min Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 11 tests passed 9 min 56 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 7 min 12 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 6 min 49 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 2 min 52 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

sre-bot avatar Oct 11 '22 08:10 sre-bot