Skip to content

Commit

Permalink
[TiDB] Add new mode option prefer-leader for tidb_replica_read. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
LykxSassinator authored Feb 10, 2023
1 parent b68dd45 commit d06b8c9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions develop/dev-guide-use-follower-read.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ aliases: ['/zh/tidb/dev/use-follower-read']
<SimpleTab>
<div label="SQL">

在 SQL 中,你可以将变量 `tidb_replica_read` 的值(默认为 `leader`)设置为 `follower` `leader-and-follower` `closest-replicas``closest-adaptive` 开启 TiDB 的 Follower Read 功能:
在 SQL 中,你可以将变量 `tidb_replica_read` 的值(默认为 `leader`)设置为 `follower``leader-and-follower``prefer-leader``closest-replicas``closest-adaptive` 开启 TiDB 的 Follower Read 功能:

```sql
SET [GLOBAL] tidb_replica_read = 'follower';
Expand All @@ -52,7 +52,8 @@ public enum FollowReadMode {
FOLLOWER("follower"),
LEADER_AND_FOLLOWER("leader-and-follower"),
CLOSEST_REPLICA("closest-replica"),
CLOSEST_ADAPTIVE("closest-adaptive");
CLOSEST_ADAPTIVE("closest-adaptive"),
PREFER_LEADER("prefer-leader");

private final String mode;

Expand Down
1 change: 1 addition & 0 deletions follower-read.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set [session | global] tidb_replica_read = '<目标值>';
- 当设置为默认值 `leader` 或者空字符串时,TiDB 会维持原有行为方式,将所有的读取操作都发送给 leader 副本处理。
- 当设置为 `follower` 时,TiDB 会选择 Region 的 follower 副本完成所有的数据读取操作。
- 当设置为 `leader-and-follower` 时,TiDB 可以选择任意副本来执行读取操作,此时读请求会在 leader 和 follower 之间负载均衡。
- 当设置为 `prefer-leader` 时,TiDB 会优先选择 leader 副本执行读取操作。当 leader 副本的处理速度明显变慢时,例如由于磁盘或网络性能抖动,TiDB 将选择其他可用的 follower 副本来执行读取操作。
- 当设置为 `closest-replicas` 时,TiDB 会优先选择分布在同一可用区的副本执行读取操作,对应的副本可以是 leader 或 follower。如果同一可用区内没有副本分布,则会从 leader 执行读取。
- 当设置为 `closest-adaptive` 时:

Expand Down
2 changes: 1 addition & 1 deletion system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -2977,7 +2977,7 @@ EXPLAIN FORMAT='brief' SELECT COUNT(1) FROM t WHERE a = 1 AND b IS NOT NULL;
- 作用域:SESSION | GLOBAL
- 是否持久化到集群:是
- 默认值:`leader`
- 可选值:`leader``follower``leader-and-follower``closest-replicas``closest-adaptive`
- 可选值:`leader``follower``leader-and-follower``prefer-leader``closest-replicas``closest-adaptive`
- 这个变量用于控制 TiDB 的 Follower Read 功能的行为。
- 关于使用方式与实现原理,见 [Follower Read](/follower-read.md)。
Expand Down

0 comments on commit d06b8c9

Please sign in to comment.