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

Atomicity may be broken for a committed transaction whose primary is locked in fair-locking mode and a stale pessimistic lock request arrives after committing #43540

Closed
Tracked by #13298
MyonKeminta opened this issue May 4, 2023 · 4 comments
Assignees
Labels
affects-7.1 severity/major sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.

Comments

@MyonKeminta
Copy link
Contributor

Bug Report

Consider the following procedure:

  1. Transaction T1 begins and locks the first key k1 in fair locking mode. k1 become the transaction's primary.
  2. Transaction T1 writes some other keys, e.g. k2.
  3. T1 commits. Its primary (k1) is successfully committed, and it reports a successful state to the client. Its secondaries are prewritten but not committed yet.
  4. Maybe some other transactions writes k1 (optional)
  5. TiKV receives a stale PessimisticLock request of step1. It successfully locks k1 since it allows locking with conflict.
  6. Transaction T2 tries to access k2, and finds T1's secondary lock. So it tries to resolve the lock.
  7. T2 calls CheckTxnStatus on k1 which is the primary of trasnaction T1.
  8. CheckTxnStatus finds the pessimistic lock of T1 on key k1. If the lock's TTL has expired (it'll happen eventually), then CheckTxnStatus will rollback the lock and return a rolled back state to the client (TiDB). Then T2 can rollback the lock on k2, which breaks T1's atomicity.

This is somewhat similar to tikv/tikv#14311 . The RPC request replaying after a long time (transaction does some retries and then successfully commit) should be very very unlikely to happen, but it's theoretically possible.

@MyonKeminta MyonKeminta added the type/bug The issue is confirmed as a bug. label May 4, 2023
@ti-chi-bot ti-chi-bot bot added may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels May 5, 2023
@MyonKeminta MyonKeminta added affects-7.1 and removed may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels May 5, 2023
ti-chi-bot bot pushed a commit to tikv/tikv that referenced this issue May 29, 2023
@MyonKeminta
Copy link
Contributor Author

Fixed by tikv/tikv#14692

@fubinzh
Copy link

fubinzh commented Jul 15, 2024

/remove-severity critical
/severity major

@fubinzh
Copy link

fubinzh commented Jul 15, 2024

/remove-label may-affects-5.4
/remove-label may-affects-6.1
/remove-label may-affects-6.5
/remove-label may-affects-7.5
/remove-label may-affects-8.1

@MyonKeminta
Copy link
Contributor Author

MyonKeminta commented Jul 18, 2024

/remove-severity critical /severity major

@fubinzh Why is this major?

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

No branches or pull requests

3 participants