Skip to content

Force close foreign key's transaction#110

Open
you06 wants to merge 2 commits intopingcap:testing_cifrom
you06:timeout-wait
Open

Force close foreign key's transaction#110
you06 wants to merge 2 commits intopingcap:testing_cifrom
you06:timeout-wait

Conversation

@you06
Copy link

@you06 you06 commented Dec 11, 2025

What's changed

Because the foreign key transaction transfer operation contains 2 transactions, the fix #104 can not handle this case.

Force close foreign key's transaction after with-txn call. This avoids a remaining opened transaction.

Root Cause

The foreign key case contains more conflict, and the transaction timeout may cause some weird execution order.

General log of jepsen bank:

[2025/12/11 03:11:07.790 +00:00] ... [GENERAL_LOG] [conn=3833593880] ... [txnStartTS=0] ... [sql="SET @@SESSION.`autocommit`=0"]
[2025/12/11 03:11:07.791 +00:00] ... [GENERAL_LOG] [conn=3833593880] ... [txnStartTS=0] ... [sql="insert into records(account_id, amount) values (7, -3), (1, 3)"]
[2025/12/11 03:11:27.725 +00:00] ... [GENERAL_LOG] [conn=3833593880] ... [txnStartTS=462794959824617487] ... [sessionTxnMode=PESSIMISTIC] [sql="SELECT @@transaction_isolation"]
[2025/12/11 03:11:27.725 +00:00] ... [GENERAL_LOG] [conn=3833593880] ... [txnStartTS=462794959824617487] ... [sessionTxnMode=PESSIMISTIC] [sql="SET @@SESSION.`tx_isolation`=_UTF8MB4'REPEATABLE-READ'"]
[2025/12/11 03:11:27.725 +00:00] ... [GENERAL_LOG] [conn=3833593880] ... [txnStartTS=462794959824617487] ... [sessionTxnMode=PESSIMISTIC] [sql=ROLLBACK]
[2025/12/11 03:11:27.729 +00:00] ... [GENERAL_LOG] [conn=3833593880] ... [txnStartTS=0] [forUpdateTS=0] ... [sql="select * from accounts where id = 7 FOR UPDATE"]

[2025/12/11 03:11:27.730 +00:00] ... [GENERAL_LOG] [conn=3833593880] ... [txnStartTS=462794965041283095] ... [sessionTxnMode=PESSIMISTIC] [sql="SET @@SESSION.`autocommit`=1"]

[2025/12/11 03:11:27.732 +00:00] ... [GENERAL_LOG] [conn=3833593880] ... [txnStartTS=0] [forUpdateTS=0] ... [sql="SET @@SESSION.`tx_isolation`=_UTF8MB4'REPEATABLE-READ'"]
[2025/12/11 03:11:27.732 +00:00] ... [GENERAL_LOG] [conn=3833593880] ... [txnStartTS=0] [forUpdateTS=0] ... [sql="select * from accounts where id = 1 FOR UPDATE"]

SET @@SESSION.autocommit=1 is executed between 2 select-for-update statements and exit the transaction unexpectedly. And the following statements are executed in single auto-commit transactions, which break the invariants easily.

Jepsen never set variables between those 2 statements.

b1 (-> c
(c/query [(str "select * from accounts where id = ? "
(:read-lock test)) from]
{:row-fn :balance})
first
(- amount))
b2 (-> c
(c/query [(str "select * from accounts where id = ? "
(:read-lock test))
to]
{:row-fn :balance})

Test

After this change, this type of invalid statement order is eliminated.

Signed-off-by: you06 <you1474600@gmail.com>
@you06
Copy link
Author

you06 commented Dec 11, 2025

The invalid statements will happen.

@you06 you06 closed this Dec 11, 2025
Signed-off-by: you06 <you1474600@gmail.com>
@you06 you06 reopened this Dec 12, 2025
@you06 you06 changed the title wait thread done when timeout Force close foreign key's transaction Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant