From 062399b87c2ad86ba15c27e5140ebd42b573dcef Mon Sep 17 00:00:00 2001 From: Ran Date: Fri, 12 Jun 2020 16:24:28 +0800 Subject: [PATCH 1/3] update pessimistic transaction --- media/pessimistic-transaction-pipelining.png | Bin 0 -> 16878 bytes pessimistic-transaction.md | 67 ++++++++++++++----- 2 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 media/pessimistic-transaction-pipelining.png diff --git a/media/pessimistic-transaction-pipelining.png b/media/pessimistic-transaction-pipelining.png new file mode 100644 index 0000000000000000000000000000000000000000..7149c374077f4bec935c7b51155726daf72f5d86 GIT binary patch literal 16878 zcmd6P1yq$=*X~9P1O%iN0SPH-DQS_ER8Sfu1f+A*AWBLppmZq`A|TRiLRv(mLpr2E zS{m-$c*662-~I1@$N0w`cb{>_@xYe-zUy6c&ZibZDoQfvurFdG5QuYfvXXZY2#h)S z*8uATd}UC%!3q9z+E89b5^;q7C#5nY5`nmkkdwTj=8~{9?5ac5w<~aX?H$HRnzMVf z_lsD@*k6%Ik!G`2(rQUcm62?+IMobTSmpGZYv(-GDAH{TkaF9=yG*Lq-N53!uME%>1X%3V{tJMi2KBpZ!zJ5 z#4mPR!~aob4kHjBg;h`(h)1p|NchgW_|j=(k*1bQ2Pqi^?;%+8`9eU|HVcmPZO1I68uU^0%8N_X{w)s1%X zwuI|Mqn5h5iKqE-qE5nxX)$qd;N#&PHi;eHR#m;}#QF$hBNGo%I5RhQ-DX7Cmms?3 zK~osHr0VtC212H7NtKRsckml9`{5FozQplb^uE)y960~PjD^v05br*9smZIm4%1(1 zI78ZIaQte^9A?&bJcx*h^z}#Gw|<;&ajX!``l5xE3O|WWucCisWTd^l{o6O!xz0Cj zNg@lhF=0Zx`|E97xRbU59C{TRRUT!pU(*HDt*)$Ww|O7lG?#ht;>G%OYe8Wl4jUA==N1+Q2L}B8{6svqRd!AZP8$!E+L8N*Qt-2jiHQja z^nXFWEa$tk-n@A;H8lm-J8oZ=o}Nzay}vry6prdw>O>NKH_BG-9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6G59Tcw z0LjpR98ti6FlWd0uRMWFG8|BaJBE7ziV0mSon0{H0$~t6@L))T3JDF?)L__jcXb7a zg^7A>a~`U}a}{(nYmT_G-3973oS}jfmUoD_-h4{806Zn>4tX>;x82!}*UUi`bR_;G zwY9JE^E<#W2LlwgdG}(Tj(HUlkPBpU;q2y>XpjK7I5{;?$egOGL$J8X;JmE&k=Onk z&}aU@fQ(+XN)AAZA(6|N1lwvG`Y$XY41Ng5h6VcWe5GinR+kn4sW z3n%vAgisY^R*z%4kafNK;?`j6={Z9$SrB|7$Fd^?2m45|{kG-79QKBDnD7Q(s<(}B zs^T+sA;e)$fB#0>yumo<8C2hcUeddZ_)>EghX9K*i`|fk-fI$HwmO?=OH& ziC&&Aqa`xdtI9==XZ>m+JVQ=S4sOata&i@d656+$5Ltv*)9|neWXwT}IgW?BfB*Cx zPI!Up@XQ8IInF@DnWR_W-F**&{d^Vc-kU-y*7~~YHj5Wm@Ohcb z?Wgu5VX&hEIq%=Uhw%Bt8!&{94)>Oeii&`qK<+w)Q+8K{Mi)ZlDaL0#wB4mFHaE-E zuM6QN*rOgE9I_M{=1dHWz3aoB;+hIk1`t9ql%;eMZzGPI!|h?s*0HwE@BC-wOci zEd&vV=oSzzzm?eN+uFWom{c+U5i&&lGM7xF+N+Y`$wEDZK~bSZ83To>Neg~)&oO&c z1SS+NdB&y5)5#gB>JRvg3cn_c+n*M-7jjbOjzAht+ZW0M5G3ZUipJkWpZ zr2n(SxLbnWk;!ZS8e?9!p3t9zQ+IAmm)Y*ia6DSOUoU5%THfCsjT}S63C{4R`rV!F z?T{7043&9p2eC?CIJL5PS8(gq0-VX36`oi#zhKzdM8f7r))$P%MV|)3Yhku>`mfgq)O;WUj>h$NvlQ4U^3P literal 0 HcmV?d00001 diff --git a/pessimistic-transaction.md b/pessimistic-transaction.md index eaa4fb453edd3..690d66412a7d2 100644 --- a/pessimistic-transaction.md +++ b/pessimistic-transaction.md @@ -7,37 +7,45 @@ aliases: ['/docs/dev/reference/transactions/transaction-pessimistic/'] # TiDB Pessimistic Transaction Model -In versions before 3.0.8, TiDB implements the optimistic transaction mode by default, in which the transaction commit might fail because of transaction conflict. To make sure that the commit succeeds, you need to modify the application and add an automatic retry mechanism. You can avoid this issue by using the pessimistic transaction mode of TiDB. +To make the usage of TiDB closer to traditional databases and reduce the cost of migration, starting from v3.0, TiDB supports the pessimistic transaction model on top of the optimistic transaction model. This document describes the features of the TiDB pessimistic transaction model. -## Usage +> **Note:** +> +> Starting from v3.0.8, the newly created TiDB clusters use the pessimistic transaction model by default. However, this does not affect your clusters if you upgrading from v3.0.7 or earlier to v3.0.8 (and later). In other words, **only newly created clusters default to using the pessimistic transaction model**. -To apply the pessimistic transaction mode, choose any of the following three methods that suits your needs: +## Switch transaction mode -- Execute the `BEGIN PESSIMISTIC;` statement to allow the transaction to apply the pessimistic transaction mode. You can write it in comment style as `BEGIN /*!90000 PESSIMISTIC */;` to make it compatible with the MySQL syntax. +You can set the transaction mode by configuring the [`tidb_txn_mode`](/tidb-specific- system-variables.md#tidb_txn_mode) system variable. The following command sets all explicit transactions (that is, non-autocommit transactions) executed by newly created sessions in the cluster to the pessimistic transaction model: -- Execute the `set @@tidb_txn_mode = 'pessimistic';` statement to allow all the explicit transactions (namely non-autocommit transactions) processed in this session to apply the pessimistic transaction mode. +{{< copyable "sql" >}} -- Execute the `set @@global.tidb_txn_mode = 'pessimistic';` statement to allow all newly created sessions of the entire cluster to apply the pessimistic transaction mode to execute explicit transactions. +```sql +set @@global.tidb_txn_mode = 'pessimistic'; +``` -After you set `global.tidb_txn_mode` to `pessimistic`, the pessimistic transaction mode is applied by default. To apply the optimistic transaction mode to the transaction, you can use any of the following three methods: +You can also explicitly enable the pessimistic transaction mode by executing the following SQL statements: -- Execute the `BEGIN OPTIMISTIC;` statement to allow the transaction to apply the optimistic transaction mode. You can write it in comment style as `BEGIN /*!90000 OPTIMISTIC */;` to make it compatible with the MySQL syntax. +{{< copyable "sql" >}} -- Execute the `set @@tidb_txn_mode = 'optimistic';` statement to allow all the transactions processed in this session to apply the optimistic transaction mode. +```sql +BEGIN PESSIMISTIC; +``` -- Execute the `set @@global.tidb_txn_mode = 'optimistic;'` or `set @@global.tidb_txn_mode = '';` to allow all newly created sessions of the entire cluster to apply the optimistic transaction mode to the transactions. +{{< copyable "sql" >}} -The `BEGIN PESSIMISTIC;` and `BEGIN OPTIMISTIC;` statements take precedence over the `tidb_txn_mode` system variable. Transactions started with these two statements ignore the system variable and support using both the pessimistic and optimistic transaction modes. +```sql +BEGIN /*!90000 PESSIMISTIC */; +``` -To disable the pessimistic transaction mode, modify the configuration file and add `enable = false` to the `[pessimistic-txn]` category. +The `BEGIN PESSIMISTIC;` and `BEGIN OPTIMISTIC;` statements take precedence over the `tidb_txn_mode` system variable. Transactions started with these two statements ignore the system variable and support using both the pessimistic and optimistic transaction modes. ## Behaviors Pessimistic transactions in TiDB behave similarly to those in MySQL. See the minor differences in [Difference with MySQL InnoDB](#difference-with-mysql-innoDB). -- When you perform the `SELECT FOR UPDATE` statement, transactions read the last committed data and apply a pessimistic lock on the data being read. +- When you perform the `SELECT FOR UPDATE` statement, transactions read the **lastest** committed data and apply a pessimistic lock on the data being read. -- When you perform the `UPDATE`, `DELETE` or `INSERT` statement, transactions read the last committed data to execute on them and apply a pessimistic lock on the modified data. +- When you perform the `UPDATE`, `DELETE` or `INSERT` statement, transactions read the **lastest** committed data to execute on them and apply a pessimistic lock on the modified data. - When a pessimistic lock is applied on a row of data, other write transactions attempting to modify the data are blocked and have to wait for the lock to be released. @@ -61,7 +69,7 @@ Pessimistic transactions in TiDB behave similarly to those in MySQL. See the min 1. When TiDB executes DML or `SELECT FOR UPDATE` statements that use range in the WHERE clause, the concurrent `INSERT` statements within the range are not blocked. - By implementing Gap Lock, InnoDB blocks the execution of concurrent `INSERT` statements within the range. It is mainly used to support statement-based binlog. Therefore, some applications lower the isolation level to READ COMMITTED to avoid concurrency performance problems caused by Gap Lock. TiDB does not support Gap Lock, so there is no need to pay the concurrency performance cost. + By implementing Gap Lock, InnoDB blocks the execution of concurrent `INSERT` statements within the range. It is mainly used to support statement-based binlog. Therefore, some applications lower the isolation level to Read Committed to avoid concurrency performance problems caused by Gap Lock. TiDB does not support Gap Lock, so there is no need to pay the concurrency performance cost. 2. TiDB does not support `SELECT LOCK IN SHARE MODE`. @@ -81,6 +89,33 @@ Pessimistic transactions in TiDB behave similarly to those in MySQL. See the min 6. The data read by `EMBEDDED SELECT` in the statement is not locked. +## Isolation level + +TiDB supports the following two isolation levels in the pessimistic transaction mode: + +- [Repeatable Read](/transaction-isolation-levels.md#repeatable-read-isolation-level) by default, which is the same as MySQL. + + > **Note:** + > + > In this isolation level, DML operations are performed based on the latest committed data. The behavior is the same as MySQL, but differs from the optimistic transaction mode in TiDB. See [Difference between TiDB and MySQL Repeatable Read](/transaction-isolation-levels.md#difference-between-tidb-and-mysql-repeatable-read). + +- [Read Committed](/transaction-isolation-levels.md#read-committed-isolation-level). You can set this isolation level using the [`SET TRANSACTION`](/sql-statements/sql-statement-set-transaction.md) statement. + +## Pipelined locking process + +Adding a pessimistic lock requires writing data into TiKV. The transaction can only be returned after commit and apply through Raft. Therefore, compared with optimistic transactions, the pessimistic transaction mode inevitably has higher latency. + +To reduce the overhead of locking, TiKV implements the pipelined locking process: when the data meets the requirements for locking, TiKV immediately notifies TiDB to execute subsequent requests and writes into the pessimistic lock asynchronously. This process reduces most latency and significantly improves the performance of pessimistic transactions. However, there is a low probability that the asynchronous write into the pessimistic lock might fail, resulting in the commit failure of the pessimistic transaction. + +![Pipelined pessimistic lock](/media/pessimistic-transaction-pipelining.png) + +This feature is disabled by default. To enable it, modify the TiKV configuration: + +```toml +[pessimistic-txn] +pipelined = true +``` + ## FAQ 1. The TiDB log shows `pessimistic write conflict, retry statement`. @@ -93,4 +128,4 @@ Pessimistic transactions in TiDB behave similarly to those in MySQL. See the min 3. The execution time limit for pessimistic transactions. - The execution time of transactions cannot exceed the limit of `tikv_gc_life_time`. In addition, the pessimistic transactions have a TTL (Time to Live) limit of 10 minutes, so the pessimistic transactions that execute over 10 minutes might fail to commit. + In TiDB 4.0, garbage collection (GC) does not affect the running transactions, but the execution time of pessimistic transactions cannot exceed 10 minutes by default. You can modify this limit by editing `max-txn-ttl` under `[performance]` in the TiDB configuration file. From b37b331fae68da6414b4f08a9ee48f41ca066cf4 Mon Sep 17 00:00:00 2001 From: Ran Date: Tue, 16 Jun 2020 10:28:55 +0800 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Keke Yi <40977455+yikeke@users.noreply.github.com> --- pessimistic-transaction.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pessimistic-transaction.md b/pessimistic-transaction.md index 690d66412a7d2..9da157fddc821 100644 --- a/pessimistic-transaction.md +++ b/pessimistic-transaction.md @@ -11,11 +11,11 @@ To make the usage of TiDB closer to traditional databases and reduce the cost of > **Note:** > -> Starting from v3.0.8, the newly created TiDB clusters use the pessimistic transaction model by default. However, this does not affect your clusters if you upgrading from v3.0.7 or earlier to v3.0.8 (and later). In other words, **only newly created clusters default to using the pessimistic transaction model**. +> Starting from v3.0.8, newly created TiDB clusters use the pessimistic transaction model by default. However, this does not affect your existing cluster if you upgrade it from v3.0.7 or earlier to v3.0.8 or later. In other words, **only newly created clusters default to using the pessimistic transaction model**. ## Switch transaction mode -You can set the transaction mode by configuring the [`tidb_txn_mode`](/tidb-specific- system-variables.md#tidb_txn_mode) system variable. The following command sets all explicit transactions (that is, non-autocommit transactions) executed by newly created sessions in the cluster to the pessimistic transaction model: +You can set the transaction mode by configuring the [`tidb_txn_mode`](/tidb-specific-system-variables.md#tidb_txn_mode) system variable. The following command sets all explicit transactions (that is, non-autocommit transactions) executed by newly created sessions in the cluster to the pessimistic transaction mode: {{< copyable "sql" >}} From d522b9b9b34eace180f3c6c5f3d13300f24a57af Mon Sep 17 00:00:00 2001 From: Keke Yi <40977455+yikeke@users.noreply.github.com> Date: Tue, 16 Jun 2020 11:49:14 +0800 Subject: [PATCH 3/3] Update pessimistic-transaction.md --- pessimistic-transaction.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pessimistic-transaction.md b/pessimistic-transaction.md index 9da157fddc821..8b7154c33af61 100644 --- a/pessimistic-transaction.md +++ b/pessimistic-transaction.md @@ -103,7 +103,7 @@ TiDB supports the following two isolation levels in the pessimistic transaction ## Pipelined locking process -Adding a pessimistic lock requires writing data into TiKV. The transaction can only be returned after commit and apply through Raft. Therefore, compared with optimistic transactions, the pessimistic transaction mode inevitably has higher latency. +Adding a pessimistic lock requires writing data into TiKV. The response of successfully adding a lock can only be returned to TiDB after commit and apply through Raft. Therefore, compared with optimistic transactions, the pessimistic transaction mode inevitably has higher latency. To reduce the overhead of locking, TiKV implements the pipelined locking process: when the data meets the requirements for locking, TiKV immediately notifies TiDB to execute subsequent requests and writes into the pessimistic lock asynchronously. This process reduces most latency and significantly improves the performance of pessimistic transactions. However, there is a low probability that the asynchronous write into the pessimistic lock might fail, resulting in the commit failure of the pessimistic transaction.