Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 悲观事务和乐观事务模型
【TiDB Usage Environment】Production\Test Environment\POC
【TiDB Version】
【Encountered Problem】
【Reproduction Path】What operations were performed to encounter the problem
【Problem Phenomenon and Impact】
How to determine whether the deployed cluster is using the pessimistic transaction model or the optimistic transaction model? The documentation mentions that it is related to the version. Besides the version, are there any parameters that control this?
Before version 3.0.8, only optimistic transactions were supported. Later, both optimistic and pessimistic transactions are supported, and the tidb_txn_mode
setting can be used.
The TiDB server layer uses pessimistic locking, but optimistic locking exists at the TiKV layer.
select @@tidb_txn_mode;
Empty means optimistic
- Query Transaction Mode
# Method 1:
mysql> show global variables like '%tidb_txn_mode%';
+---------------+-------------+
| Variable_name | Value |
+---------------+-------------+
| tidb_txn_mode | pessimistic |
+---------------+-------------+
1 row in set (0.00 sec)
# Method 2:
mysql> select @@tidb_txn_mode;
+-----------------+
| @@tidb_txn_mode |
+-----------------+
| pessimistic |
+-----------------+
1 row in set (0.00 sec)
- Modify Transaction Mode
SET GLOBAL tidb_txn_mode ='pessimistic';
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.