Force close foreign key's transaction
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.
https://github.com/pingcap/jepsen/blob/dae83e6020806c7eb4962104715e8239e236c089/tidb/src/tidb/bank.clj#L106-L116
Test
After this change, this type of invalid statement order is eliminated.