1.6 Read and Write data in the TiDB database platform

  |   0 评论   |   0 浏览

1.6 Read and Write data in the TiDB database platform(TiDB 中的读写流程)

主讲人

Gang Shen(沈刚)

Community Tech Center DBA

Woqu / PingCAP

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

161TiDBOverview.png

Subtopic: TiDB

  • Introduction of TiDB

162IntroductionofTiDB.png

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

163IntroductionofPD.png

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

164SQLProcessingFlow.png

Read request in TiDB

  1. The client establish connection to TiDB and send a request to TiDB
  2. TiDB gets SQL from the request
  3. TiDB parses and compiles the SQL, make and optimize the query plan
  4. TiDB gets start_ts from PD
  5. TiDB gets the metadata of table and transfers the query plan to a series of executor
  6. TiDB sends the coprocessor request to TiKV through gRPC
  7. TiKV receives the request, searches for the data, and sends the result to TiDB
  8. TiDB receives all the data from TiKV and handles the result
  9. 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

  1. The client establish connection to TiDB and send a request to TiDB
  2. TiDB gets SQL from the request
  3. TiDB parses and compiles the SQL, make and optimize the query plan
  4. TiDB gets start_ts from PD
  5. TiDB gets the metadata of table and transfers the query plan to a series of executor
  6. TiDB make a commit request
  7. TiKV commit the data using two-phase commit(prewrite/commit) according to the percolator, TiDB will gets commit_ts at commit phase(2PC)
  8. TiKV send the result to TiDB
  9. TiDB send the result to client