当前位置:网站首页>TiDB 6.0:让 TSO 更高效丨TiDB Book Rush
TiDB 6.0:让 TSO 更高效丨TiDB Book Rush
2022-06-27 11:46:00 【InfoQ】
1. 前言
- TSO 分配由 PD Leader 节点提供,大量请求下会导致 Leader 节点 CPU 利用率增高,影响事务延迟。
- PD Follower 节点基本处于空闲状态,系统资源利用率较低。
- TiDB 跨数据中心访问 PD Leader 时,数据中心间的延迟导致事务延迟增加。
2. TSO

3. Follower Proxy

4. RC Read TSO 优化
- Select 语句执行时不从 PD 获取 TSO 作为 for_update_ts,而是使用上一个有效的 TSO 作为 for_update_ts(即为 read_ts)。如果是事务中的第一个语句则是 start_ts,否则是上一个 SQL 的 for_update_ts。
- 构建执行计划并执行,发送到 tikv 的数据读取请求(pointget、coprocessor)会带上 RcReadCheckTS 标志。
- 数据读取请求使用前面获得的 read_ts 做一致性读取,并将数据返回 tidb server。
- TiKV 会检查返回的数据是否有更新版本,如果有更新的版本则返回 WriteConflict 错误,否则返回数据后正常结束执行。
- 如果此时 tidb 还未向 client 发送数据则会从 PD 获取最新的 TSO 作为 for_update_ts 重新执行整个查询,否则会向 client 返回错误。
5. Local TSO
- Local TSO
- Global TSO
- Global tso allocator 收集所有 local tso allocator 的最大 local tso。
- 从所有 local tso 中选出一个最大的 local tso 作为 max_tso 下发到 local allocator。
- 如果 max_tso 比自己的大则更新 TSO 为 max_tso,否则直接返回成功。
- PD、TiKV、TiDB server 均需要根据实际部署设置 label,为保证高可用每个 DC 的 PD 数量应>1。


- 开启库或表级 Placement Rules in SQL,根据地域和业务关系进行调度。
CREATE PLACEMENT POLICY dc1_leader LEADER_CONSTRAINTS="DC1" FOLLOWER_CONSTRAINTS="DC1,DC2,DC3" FOLLOWERS=2; Alter table new_order PARTITION p0 PLACEMENT POLICY dc1_leaders;- 设置 PD 参数 enable-local-tso=on 使用 tiup reload 重启 PD 开启 Local TSO 功能。启用之后可通过 pd-ctl -u pd_ip:pd_port member 中 tso_allocator_leaders 项内容查看每个中心的 local tso allocator leader。
6. 测试
6.1 测试环境

6.2 TSO Follower Proxy


6.3 RC Read TSO


6.4 Local TSO

7. 总结
边栏推荐
猜你喜欢

pull request

57. The core principle of flutter - layout process

Unity Shader学习(二)第一个Shader

In 2021, the global carbon graphite brush revenue is about US $2366million, and it is expected to reach US $2701.8 million in 2028

Qstype implementation of self drawing interface project practice (I)

Research Report on the overall scale, major manufacturers, major regions, products and application segments of hydraulic torque in the global market in 2022

In 2021, the global professional liability insurance revenue was about USD 44740million, and it is expected to reach USD 55980million in 2028. From 2022 to 2028, the CAGR was 3.5%

Summary of qstype class usage (II)

Topic37——64. 最小路径和

如何修改 node_modules 裏的文件
随机推荐
After Jerry's sleep, the regular wake-up system continues to run without resetting [chapter]
AUTOCAD——三种修剪方式
Salesforce 容器化 ISV 场景下的软件供应链安全落地实践
Youboxun attended the openharmony technology day to create a new generation of secure payment terminals
R语言fpc包的dbscan函数对数据进行密度聚类分析、plot函数可视化聚类图
MapReduce practical cases (customized sorting, secondary sorting, grouping, zoning)
56. Core principle of flutter - flutter startup process and rendering pipeline
Unity shader learning (II) the first shader
Drive to APasS! Use Mingdao cloud to manage F1 events
1. Mx6ull startup mode
This privatized deployed enterprise knowledge base makes telecommuting a zero distance
如何修改 node_modules 里的文件
Maximum path and problem (cherry picking problem)
最大路径和问题(摘樱桃问题)
Online bidding of Oracle project management system
千万不要错过,新媒体运营15个宝藏公众号分享
Jerry's constant feeding of dogs will cause frequent switch interruptions leading to timer [chapter]
[on Nacos] get started quickly
动态规划【四】(计数类dp)例题:整数划分
想学好C语言,操作符也很重要
