当前位置:网站首页>TiKV Follower Read
TiKV Follower Read
2022-07-17 14:46:00 【添香小铺】
当系统中存在读取热点 Region 导致 leader 资源紧张成为整个系统读取瓶颈时,启用 Follower Read 功能可明显降低 leader 的负担,并且通过在多个 follower 之间均衡负载,显著地提升整体系统的吞吐能力。本文主要介绍 Follower Read 的使用方法与实现机制。
概述
Follower Read 功能是指在强一致性读的前提下使用 Region 的 follower 副本来承载数据读取的任务,从而提升 TiDB 集群的吞吐能力并降低 leader 负载。Follower Read 包含一系列将 TiKV 读取负载从 Region 的 leader 副本上 offload 到 follower 副本的负载均衡机制。TiKV 的 Follower Read 可以保证数据读取的一致性,可以为用户提供强一致的数据读取能力。
注意
为了获得强一致读取的能力,在当前的实现中,follower 节点需要向 leader 节点询问当前的执行进度(即 ReadIndex),这会产生一次额外的网络请求开销,因此目前 Follower Read 的主要优势是处理隔离集群的读写请求以及提升整体读取吞吐。
使用方式
要开启 TiDB 的 Follower Read 功能,将变量 tidb_replica_read 的值设置为 follower 或 leader-and-follower 即可:
set [session | global] tidb_replica_read = '<目标值>';
作用域:SESSION | GLOBAL
默认值:leader
该变量用于设置期待的数据读取方式。
- 当设定为默认值
leader或者空字符串时,TiDB 会维持原有行为方式,将所有的读取操作都发送给 leader 副本处理。 - 当设置为
follower时,TiDB 会选择 Region 的 follower 副本完成所有的数据读取操作。 - 当
tidb_replica_read的值设为leader-and-follower时,TiDB 可以选择任意副本来执行读取操作。 - 当设置为
leader-and-follower时,读请求会在 leader 和 follower 之间负载均衡。
实现机制
在 Follower Read 功能出现之前,TiDB 采用 strong leader 策略将所有的读写操作全部提交到 Region 的 leader 节点上完成。虽然 TiKV 能够很均匀地将 Region 分散到多个物理节点上,但是对于每一个 Region 来说,只有 leader 副本能够对外提供服务,另外的 follower 除了时刻同步数据准备着 failover 时投票切换成为 leader 外,没有办法对 TiDB 的请求提供任何帮助。
为了允许在 TiKV 的 follower 节点进行数据读取,同时又不破坏线性一致性和 Snapshot Isolation 的事务隔离,Region 的 follower 节点需要使用 Raft ReadIndex 协议确保当前读请求可以读到当前 leader 上已经 commit 的最新数据。在 TiDB 层面,Follower Read 只需根据负载均衡策略将某个 Region 的读取请求发送到 follower 节点。
Follower 强一致读
TiKV follower 节点处理读取请求时,首先使用 Raft ReadIndex 协议与 Region 当前的 leader 进行一次交互,来获取当前 Raft group 最新的 commit index。本地 apply 到所获取的 leader 最新 commit index 后,便可以开始正常的读取请求处理流程。
Follower 副本选择策略
由于 TiKV 的 Follower Read 不会破坏 TiDB 的 Snapshot Isolation 事务隔离级别,因此 TiDB 选择 follower 的策略可以采用 round robin 的方式。目前,对于 Coprocessor 请求,Follower Read 负载均衡策略粒度是连接级别的,对于一个 TiDB 的客户端连接在某个具体的 Region 上会固定使用同一个 follower,只有在选中的 follower 发生故障或者因调度策略发生调整的情况下才会进行切换。而对于非 Coprocessor 请求(点查等),Follower Read 负载均衡策略粒度是事务级别的,对于一个 TiDB 的事务在某个具体的 Region 上会固定使用同一个 follower,同样在 follower 发生故障或者因调度策略发生调整的情况下才会进行切换。
边栏推荐
- 466-82(3、146、215)
- Tier defect detection using full revolutionary network
- 466-82(3、146、215)
- ThreadLocal变量使用及原理
- Unity高版本退回低版本报错问题
- MySQL cannot be started? Relevant components missing? System upgrade? Component mismatch? Start reinstalling MySQL
- Will causal learning open the next generation of AI? Chapter 9 Yunji datacanvas officially released the open source project of ylarn causal learning
- What happened to cinder in openstack-m
- 8.固定收益投资
- Unity dropdown (editable, inputable) drop-down selection box with Text Association
猜你喜欢

Docker install MySQL

A fastandrobust convolutionalneuralnetwork-based defect detection model inproductqualitycontrol-阅读笔记

Deep Learning for Generic Object Detection: A Survey-论文阅读笔记

XSS. haozi. Me brush questions
![[untitled] CV learning 1 conversion](/img/22/55d171f49659e704951ebd82a33f06.png)
[untitled] CV learning 1 conversion

Tier defect detection using full revolutionary network

Delegate parents and other loaders

SPI服务发现机制

TCP拥塞控制详解 | 7. 超越TCP
![[PostgreSQL] PostgreSQL 15 optimizes distinct](/img/7c/89d05171902dd88bd2b5c352c3614f.png)
[PostgreSQL] PostgreSQL 15 optimizes distinct
随机推荐
A current List of AWESOME Qt and qml
LeetCode 558. Intersection of quadtree
Delegate parents and other loaders
每日刷题记录 (二十六)
The basic establishment of the sequence table and the related operations of adding, deleting, modifying and querying (the sequence table described in C language)
Daily question brushing record (26)
An error, uncaught typeerror: modalfactory is not a constructor
Antd form setting array fields
02-3、指针和引用的区别
Unity dropdown (editable, inputable) drop-down selection box with Text Association
Deep learning for generic object detection: a survey
Set the interface language of CMD command prompt window to English
ThreadLocal变量使用及原理
Similarities and differences between OA system and MES system
Tier defect detection using full revolutionary network
02-3. Difference between pointer and reference
[multithreading] detailed explanation of JUC (callable interface, renntrantlock, semaphore, countdownlatch), thread safe set interview questions
Will causal learning open the next generation of AI? Chapter 9 Yunji datacanvas officially released the open source project of ylarn causal learning
A curated list of awesome Qt and QML
Developing those things: how to solve the problem of long-time encoding and decoding of RK chip video processing?