Pessimistic Transaction and Optimistic Transaction Models

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 悲观事务和乐观事务模型

| username: 胡杨树旁

【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?

| username: h5n1 | Original post link

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.

| username: 近墨者zyl | Original post link

The TiDB server layer uses pessimistic locking, but optimistic locking exists at the TiKV layer.

| username: WalterWj | Original post link

select @@tidb_txn_mode; Empty means optimistic

| username: OnTheRoad | Original post link

  1. 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)
  1. Modify Transaction Mode
SET GLOBAL tidb_txn_mode ='pessimistic';
| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.