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

[TiDB] Add new mode option prefer-leader for tidb_replica_read. #12865

Merged
merged 4 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -2962,7 +2962,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