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

Report write-conflict error in pessimistic transactions #25964

Closed
youjiali1995 opened this issue Jul 5, 2021 · 1 comment · Fixed by #25984
Closed

Report write-conflict error in pessimistic transactions #25964

youjiali1995 opened this issue Jul 5, 2021 · 1 comment · Fixed by #25984
Assignees
Labels
severity/major sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.

Comments

@youjiali1995
Copy link
Contributor

youjiali1995 commented Jul 5, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. Enable async-commit.
  2. Make two transactions conflict on the non-unique secondary index, for example, one transaction inserts a row and the other delete it. Because pessimistic transaction in TiDB doesn't acquire pessimistic locks on the non-unique secondary index, it's possible the second transaction conflicts with the former one while prewriting, and it resolves the lock immediately because of the special logic for resolving non-pessimistic lock conflict: https://github.com/tikv/tikv/blob/54ac25ca0d100fb5969eb0c30290eeb5b65159ff/src/storage/txn/actions/prewrite.rs#L238-L248
  3. The lock isn't resolved because it uses async-commit protocol and it isn't expired.
  4. The former version TiDB assumes that pessimistic transaction is able to resolve all non-pessimistic locks while prewriting which is not true since v5.0 due to async-commit. TiDB wrongly handles such a case and return a write-conflict error: https://github.com/tikv/client-go/blob/d0a98864a6ac4df1e229f89b9f79fe8bc20febb2/tikv/lock_resolver.go#L415-L423.

2. What did you expect to see? (Required)

The transaction commit successfully.

3. What did you see instead (Required)

[2021/07/05 12:35:17.448 +08:00] [INFO] [prewrite.go:310] ["prewrite encounters lock"] [session=1343] [lock="key: 7480000000000000405f6980000000000000010380000000005f489b0380000000004cc096, primary: 7480000000000000765f7280000000004d2186, txnStartTS: 426104512050627094, lockForUpdateTS:426104512050627094, minCommitTs:426104512116425201, ttl: 0, type: Put, UseAsyncCommit: true"]
[2021/07/05 12:35:17.450 +08:00] [WARN] [session.go:605] ["can not retry txn"] [conn=1343] [label=general] [error="[kv:9007]Write conflict, txnStartTS=426104512037519522, conflictStartTS=426104512050627094, conflictCommitTS=0, key={tableID=64, indexID=1, indexValues={6244507, 5030038, }} primary=[]byte(nil) [try again later]"] [IsBatchInsert=false] [IsPessimistic=true] [InRestrictedSQL=false] [tidb_retry_limit=10] [tidb_disable_txn_auto_retry=true]
[2021/07/05 12:35:17.450 +08:00] [WARN] [session.go:621] ["commit failed"] [conn=1343] ["finished txn"="Txn{state=invalid}"] [error="[kv:9007]Write conflict, txnStartTS=426104512037519522, conflictStartTS=426104512050627094, conflictCommitTS=0, key={tableID=64, indexID=1, indexValues={6244507, 5030038, }} primary=[]byte(nil) [try again later]"]
[2021/07/05 12:35:17.450 +08:00] [INFO] [conn.go:877] ["command dispatched failed"] [conn=1343] [connInfo="id:1343, addr:172.16.6.48:42149 status:10, collation:latin1_swedish_ci, user:root"] [command=Execute] [status="inTxn:0, autocommit:1"] [sql=COMMIT] [txn_mode=PESSIMISTIC] [err="[kv:9007]Write conflict, txnStartTS=426104512037519522, conflictStartTS=426104512050627094, conflictCommitTS=0, key={tableID=64, indexID=1, indexValues={6244507, 5030038, }} primary=[]byte(nil) [try again later]\nCOMMIT"]

4. What is your TiDB version? (Required)

v5.0.0-v5.0.3, v5.1.0

@ti-srebot
Copy link
Contributor

ti-srebot commented Jul 6, 2021

Please edit this comment or add a new comment to complete the following information

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

Committing pessimistic transactions report write-conflict errors.

3. All Trigger Conditions (optional)

Please refer to the issue description.

4. Workaround (optional)

None.

5. Affected versions

[v5.0.0:v5.0.3], v5.1.0

6. Fixed versions

v5.0.4, v5.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/major sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants