1.6 Read and Write data in the TiDB database platform
1.6 Read and Write data in the TiDB database platform(TiDB 中的读写流程)
主讲人:
Gang Shen(沈刚)
Community Tech Center DBA
MySQL & TiDB
Before we begin
- Context: Want to know more about TiDB
- Goal
- Have a certain understanding of TiDB's overall architecture
- Understand TiDB's general processing flow for read and write requests
- Outline
- Introduction of TiDB Platform
- Read Request in TiDB
- Write Request in TiDB
Part I: Introduction of TiDB Platform
- A overview of TiDB Platform
- Goal
- Subtopics
- TiDB
- TiKV
- PD
- Key points
- Review of goal
TiDB Overview
Subtopic: TiDB
- Introduction of TiDB
TiDB 本身不提供负载均衡功能。
Subtopic: TiKV
- Introduction of TiKV
- Distributed Key-Value storage engine
- Snapshot Isolation
- Raft protocol
- Not dependent on distributed file system
基于 Raft 协议的分布式存储引擎,具有高度分层的特性:
- Transaction -- 事务层
- MVCC -- 提供多版本并发控制特性
- Raft -- 该层保证数据一致性
- Local KV Storage -- 底层存储
Subtopic: PD
- Introduction of PD
Part II: Read Request in TiDB
- Introduction of TiDB Platform
- Goal
- Subtopics
- SQL Processing Flow
- Read Request in TiDB
- Key points
- Review of goal
SQL Processing Flow
Read request in TiDB
- The client establish connection to TiDB and send a request to TiDB
- TiDB gets SQL from the request
- TiDB parses and compiles the SQL, make and optimize the query plan
- TiDB gets start_ts from PD
- TiDB gets the metadata of table and transfers the query plan to a series of executor
- TiDB sends the coprocessor request to TiKV through gRPC
- TiKV receives the request, searches for the data, and sends the result to TiDB
- TiDB receives all the data from TiKV and handles the result
- TiDB sends the result to the client
Part III: Write Request in TiDB
- Introduction of TiDB Platform
- Goal
- Subtopics
- Write Request in TiDB
- Key points
- Review of goal
Write request in TiDB
- The client establish connection to TiDB and send a request to TiDB
- TiDB gets SQL from the request
- TiDB parses and compiles the SQL, make and optimize the query plan
- TiDB gets start_ts from PD
- TiDB gets the metadata of table and transfers the query plan to a series of executor
- TiDB make a commit request
- TiKV commit the data using two-phase commit(prewrite/commit) according to the percolator, TiDB will gets commit_ts at commit phase(2PC)
- TiKV send the result to TiDB
- TiDB send the result to client