Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reference: update v2.1 auto-retry description #2111

Merged
merged 4 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
reference: update v2.1 auto-retry description
  • Loading branch information
TomShawn committed Dec 10, 2019
commit 15808025000bb5388fb69c2902c756e5ead073b6
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ set @@global.tidb_distsql_scan_concurrency = 10

作用域:SESSION | GLOBAL

默认值:on
默认值:off

这个变量用来设置是否禁用显式事务自动重试,设置为 `on` 时,不会自动重试,如果遇到事务冲突需要在应用层重试。

如果将该变量的值设为 `off`,TiDB 将会自动重试事务,这样在事务提交时遇到的错误更少。需要注意的是,这样可能会导致数据更新丢失。
如果将该变量的值设为 `off`,TiDB 将会自动重试事务,这样在事务提交时遇到的错误更少。需要注意的是,这样可能会导致数据更新丢失。TiDB v2.1 默认开启自动重试。

这个变量不会影响自动提交的隐式事务和 TiDB 内部执行的事务,它们依旧会根据 `tidb_retry_limit` 的值来决定最大重试次数。

Expand Down
6 changes: 4 additions & 2 deletions v2.1/reference/transactions/transaction-isolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TiDB 实现了快照隔离 (Snapshot Isolation) 级别的一致性。为与 MySQ

> **注意:**
>
> 在 2.1 默认设置中,事务的自动重试功能默认开启。关于该项功能对隔离级别的影响以及如何开启该项功能,请参考[事务自动重试及带来的异常](#事务自动重试及带来的异常)。
> 在 2.1 默认设置中,事务的自动重试功能默认开启。关于该项功能对隔离级别的影响以及如何关闭该项功能,请参考[事务自动重试及带来的异常](#事务自动重试及带来的异常)。

TiDB 使用 [Percolator 事务模型](https://research.google.com/pubs/pub36726.html),当事务启动时会获取全局读时间戳,事务提交时也会获取全局提交时间戳,并以此确定事务的执行顺序,如果想了解 TiDB 事务模型的实现可以详细阅读以下两篇文章:[TiKV 的 MVCC (Multi-Version Concurrency Control) 机制](https://pingcap.com/blog-cn/mvcc-in-tikv/),[Percolator 和 TiDB 事务算法](https://pingcap.com/blog-cn/percolator-and-txn/)。

Expand Down Expand Up @@ -53,7 +53,9 @@ MySQL 可重复读隔离级别在更新时并不检验当前版本是否可见

## 事务自动重试及带来的异常

TiDB 默认进行事务自动重试,重试事务可能会导致更新丢失,从而破坏快照隔离。如果业务可以容忍事务重试导致的异常,或并不关注事务是否以快照隔离级别来执行,则可以开启自动重试。通过设置 `tidb_disable_txn_auto_retry = off` 可开启该项功能。需注意 `tidb_retry_limit` 的值不能为 `0`,否则会禁用自动重试。开启自动重试以后,事务遇到提交出错的可能性会降低。
TiDB v2.1 默认进行事务自动重试。重试事务可能会导致更新丢失,从而破坏快照隔离。如果业务可以容忍事务重试导致的异常,或并不关注事务是否以快照隔离级别来执行,则可以保持开启自动重试。开启自动重试以后,事务遇到提交出错的可能性会降低。

若要关闭自动重试,可设置 `tidb_disable_txn_auto_retry = on`。若将 `tidb_retry_limit` 设为 `0`,可禁用自动重试。

开启自动重试后,显式事务遇到冲突可能会导致最终结果不符合预期。

Expand Down