Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 悲观模式下写写冲突测试的疑问
【TiDB Usage Environment】Production, Testing, Research
【TiDB Version】
【Encountered Problem】
The current environment is in pessimistic transaction mode. Why does the following test result in a write-write conflict message when session1 commits its transaction after session2 has already committed?
mysql>
mysql> show variables like '%txn_mode%';
+---------------+-------------+
| Variable_name | Value |
+---------------+-------------+
| tidb_txn_mode | PESSIMISTIC |
+---------------+-------------+
1 row in set (0.01 sec)
mysql> show create table zjp;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| zjp | CREATE TABLE `zjp` (
`id` int(11) NOT NULL,
`name` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
SESSION1: Start transaction
mysql>
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
SESSION2: Update record with id=13
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> update zjp set name=‘ABC’ where id=13;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
SESSION1: Update record with id=13, backend log reports write conflict
mysql> update zjp set name=‘ABC’ where id=13;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
tidb.log
[2022/08/09 10:57:24.191 +08:00] [INFO] [adapter.go:633] [“pessimistic write conflict, retry statement”] [conn=446] [txn=435162658714681346] [forUpdateTS=435162658714681346] [err=“[kv:9007]Write conflict, txnStartTS=435162658714681346, conflictStartTS=435162659501113346, conflictCommitTS=435162668178079745, key={tableID=534, handle=12} primary={tableID=534, handle=12} [try again later]”]
【Reproduction Path】What operations were performed to encounter the problem
【Problem Phenomenon and Impact】
【Attachments】
Please provide the version information of each component, such as cdc/tikv, which can be obtained by executing cdc version/tikv-server --version.