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

tools, toc: reorganize TiDB Binlog documents #1264

Merged
merged 113 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
5a17f6e
reorg the binlog documents
ericsyh Apr 23, 2019
7155c89
fix some errors in overview
ericsyh Apr 23, 2019
1e241e1
fix similar problems
ericsyh Apr 23, 2019
6d7080b
update the TOC
ericsyh Apr 23, 2019
52133dc
fix an format error in deployment
ericsyh Apr 24, 2019
dc6bd0d
1. update the document title 2. fix the pic link error in kafka & 1.0…
ericsyh Apr 24, 2019
8ec63c1
update TOC format
ericsyh Apr 24, 2019
986f1fe
Update tools/binlog/overview.md
IANTHEREAL Apr 25, 2019
68cfb3a
Merge remote-tracking branch 'reorg/tidb-binlog-reorg' into tidb-binl…
ericsyh Apr 25, 2019
39016fa
change the pd to file in overview
ericsyh Apr 25, 2019
57ea746
update the ansible-deployment link
ericsyh Apr 25, 2019
d532c6e
rename the previous version of tidb-binlog to tidb-binlog-local
ericsyh Apr 25, 2019
5767957
Update tools/binlog/overview.md
lilin90 Apr 25, 2019
5edcac7
Update tools/binlog/deploy.md
lilin90 Apr 25, 2019
97d17f0
Update tools/binlog/overview.md
lilin90 Apr 25, 2019
0782031
Update tools/binlog/deploy.md
lilin90 Apr 25, 2019
8e5fdd0
Make the explaination of pausing and paused more clear
ericsyh Apr 25, 2019
51bc4cb
change the order in TOC
ericsyh Apr 25, 2019
bc86fbe
uncomment some necessary configs in kafka version
ericsyh Apr 25, 2019
ed25cce
add more explaination of paused and offline in overview
ericsyh Apr 25, 2019
a34d893
Merge remote-tracking branch 'docs-cn/master' into tidb-binlog-reorg
ericsyh Apr 25, 2019
d2de9c3
Update tools/binlog/overview.md
lilin90 Apr 26, 2019
2476f0c
Merge remote-tracking branch 'docs-cn/master' into tidb-binlog-reorg
ericsyh Apr 26, 2019
7e117c1
Keep the title consistent with the 1st level heading
ericsyh Apr 26, 2019
7bf186f
Update TOC.md
csuzhangxc Apr 28, 2019
36ba47d
Update tools/binlog/overview.md
IANTHEREAL Apr 28, 2019
ffc5987
Update tools/binlog/overview.md
IANTHEREAL Apr 28, 2019
3967136
Update tools/binlog/binlog-slave-client.md
csuzhangxc Apr 28, 2019
0680727
Update tools/binlog/binlog-slave-client.md
IANTHEREAL Apr 28, 2019
e097aba
Update tools/binlog/overview.md
IANTHEREAL Apr 28, 2019
e044957
Update tools/binlog/overview.md
IANTHEREAL Apr 28, 2019
2312f27
Update tools/binlog/binlog-slave-client.md
IANTHEREAL Apr 28, 2019
ea85973
Update tools/binlog/binlog-slave-client.md
IANTHEREAL Apr 28, 2019
66c18a5
Update tools/binlog/binlog-slave-client.md
IANTHEREAL Apr 28, 2019
1cd07e5
Update tools/binlog/binlog-slave-client.md
IANTHEREAL Apr 28, 2019
ba4c355
put the metrics intro into table
ericsyh Apr 28, 2019
81d3b51
Update tools/binlog/operation.md
IANTHEREAL Apr 28, 2019
445e3f0
Update tools/binlog/operation.md
IANTHEREAL Apr 28, 2019
8d37f2a
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
a292a60
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
9193cf7
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
fb11f60
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
3b841e5
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
d240979
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
e17ff0a
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
6a0fb0d
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
fbeeca9
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
68a180f
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
27ead46
Update tools/binlog/operation.md
IANTHEREAL Apr 28, 2019
0aa030b
Update tools/binlog/operation.md
IANTHEREAL Apr 28, 2019
23c06c8
Update tools/binlog/deploy.md
IANTHEREAL Apr 28, 2019
da3bc52
fix the typo
ericsyh Apr 28, 2019
ee49c0f
Add the Topic config in Kafka driver
ericsyh Apr 28, 2019
9242188
update the gc intro in deployment
ericsyh Apr 28, 2019
4359073
remove unnecessary step in deployment
ericsyh Apr 28, 2019
622a0c3
update pump2/3 server deploy_dir
ericsyh Apr 28, 2019
13d4d07
Update tools/binlog/overview.md
csuzhangxc Apr 28, 2019
6bec4a2
Update tools/binlog/tidb-binlog-kafka.md
csuzhangxc Apr 28, 2019
2d3d1f5
Update tools/binlog/tidb-binlog-kafka.md
csuzhangxc Apr 28, 2019
6caec92
fix the format of table
ericsyh Apr 28, 2019
595e04e
Update tools/binlog/tidb-binlog-kafka.md
csuzhangxc Apr 28, 2019
7116064
fix some ditto problems
ericsyh Apr 28, 2019
5fb1321
fix the invalid link
ericsyh Apr 28, 2019
955cec0
make words in kafka version more accurate
ericsyh Apr 28, 2019
ec33368
migrate some Notice info in overview into certain parts
ericsyh Apr 28, 2019
41d7385
fix the missed typo
ericsyh Apr 28, 2019
4016e00
update some ditto mistakes
ericsyh Apr 28, 2019
7e51032
add the file drainer config in Binlog Slave Client
ericsyh Apr 28, 2019
d15ab05
remove the file drainer
ericsyh Apr 28, 2019
eec67c8
Update tools/binlog/deploy.md
lilin90 Apr 28, 2019
47307c3
Update tools/binlog/overview.md
lilin90 Apr 28, 2019
56a8b74
Update tools/binlog/deploy.md
lilin90 Apr 28, 2019
1261b8b
Update tools/binlog/deploy.md
lilin90 Apr 28, 2019
4034219
Update tools/binlog/monitor.md
lilin90 Apr 28, 2019
6c83fb5
Update tools/binlog/operation.md
lilin90 Apr 28, 2019
4797ffb
Update tools/binlog/deploy.md
lilin90 Apr 28, 2019
3461745
Update tools/binlog/overview.md
lilin90 Apr 28, 2019
371a139
format update
ericsyh Apr 28, 2019
c0d7191
Update tools/binlog/monitor.md
lilin90 Apr 28, 2019
9dc93ba
Update tools/binlog/overview.md
lilin90 Apr 28, 2019
bf891b2
Update tools/binlog/operation.md
lilin90 Apr 28, 2019
bfcf693
Update tools/binlog/monitor.md
lilin90 Apr 28, 2019
f00ec29
update several documents
ericsyh Apr 28, 2019
0fcf045
Merge remote-tracking branch 'origin/tidb-binlog-reorg' into tidb-bin…
ericsyh Apr 28, 2019
57f01a2
Update tools/binlog/overview.md
lilin90 Apr 28, 2019
79029b7
remove the unnecessary sentence
ericsyh Apr 28, 2019
32cf939
update capital letter in binlog-slave-client
ericsyh Apr 28, 2019
70314bc
update drainer_file alias name in deploy document
ericsyh Apr 28, 2019
2100bfc
remove the compression in deploy document
ericsyh Apr 28, 2019
6a38919
remove sql in the file dainer
ericsyh Apr 28, 2019
e5747dc
update the doanload link in deployment
ericsyh Apr 28, 2019
8f72a81
Time and size limits delete
ericsyh Apr 28, 2019
98c6299
abandon enable-tolerant config
ericsyh Apr 28, 2019
b1df007
move the reparo document into binlog
ericsyh Apr 28, 2019
6cf8229
remove the previous documents
ericsyh Apr 28, 2019
af70a26
update the rapero download link
ericsyh Apr 29, 2019
26d6d8a
update drainer_pd to drainer_file
ericsyh Apr 29, 2019
a8d1494
change ; to 。in operaton document
ericsyh Apr 29, 2019
0c72dcc
Update tools/binlog/overview.md
lilin90 Apr 29, 2019
8c7ff52
update photo link in kafka and local
ericsyh Apr 29, 2019
d0d8748
Merge remote-tracking branch 'origin/tidb-binlog-reorg' into tidb-bin…
ericsyh Apr 29, 2019
b000e96
Update operation.md
WangXiangUSTC Apr 29, 2019
2e22175
Update tools/binlog/overview.md
lilin90 Apr 29, 2019
4c0b75a
Update tools/binlog/overview.md
lilin90 Apr 29, 2019
b716fe8
Update tools/binlog/tidb-binlog-local.md
lilin90 Apr 29, 2019
27df2b2
Update tools/binlog/tidb-binlog-local.md
lilin90 Apr 29, 2019
fb8d50e
Update tools/binlog/tidb-binlog-kafka.md
lilin90 Apr 29, 2019
b68e3d0
Update tools/binlog/tidb-binlog-kafka.md
lilin90 Apr 29, 2019
14c61dd
Update tools/binlog/operation.md
lilin90 Apr 29, 2019
e43cdf0
Update tools/binlog/deploy.md
lilin90 Apr 29, 2019
628a023
Update tools/binlog/upgrade.md
lilin90 Apr 29, 2019
d46a483
Update operation.md
WangXiangUSTC Apr 29, 2019
ca04d33
Update tools/binlog/operation.md
lilin90 Apr 29, 2019
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
7 changes: 6 additions & 1 deletion TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@
- [表库过滤](tools/lightning/filter.md)
- [CSV 支持](tools/lightning/csv.md)
- [监控告警](tools/lightning/monitor.md)
- [TiDB-Binlog](tools/tidb-binlog-cluster.md)
+ TiDB-Binlog
- [概述](tools/binlog/overview.md)
- [部署使用](tools/binlog/deploy.md)
ericsyh marked this conversation as resolved.
Show resolved Hide resolved
- [版本升级](tools/binlog/upgrade.md)
ericsyh marked this conversation as resolved.
Show resolved Hide resolved
- [运维管理](tools/binglog/operation.md)
- [监控告警](tools/binlog/monitor.md)
- [PD Control](tools/pd-control.md)
- [PD Recover](tools/pd-recover.md)
- [TiKV Control](https://github.com/tikv/tikv/blob/master/docs/tools/tikv-control.md)
Expand Down
147 changes: 147 additions & 0 deletions tools/binlog/binlog-slave-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
---
title: Binlog Slave Client 用户文档
category: tools
---

# Binlog Slave Client 用户文档

目前 Drainer 提供了多种输出方式,包括 MySQL、TiDB、TheFlash、pb 格式文件等。但是用户往往有一些自定义的需求,比如输出到 Elasticsearch、Hive 等,这些需求 Drainer 现在还没有实现,因此 Drainer 增加了输出到 Kafka 的功能,将 binlog 数据解析后按一定的格式再输出到 Kafka 中,用户编写代码从 Kafka 中读出数据再进行处理。
ericsyh marked this conversation as resolved.
Show resolved Hide resolved

## 配置 Drainer

修改 Drainer 的配置文件,设置输出为 Kafka,相关配置如下:

```
[syncer]
db-type = "kafka"

[syncer.to]
# Kafka 地址
kafka-addrs = "127.0.0.1:9092"
# Kafka 版本号
kafka-version = "0.8.2.0"
```

## 自定义开发

### 数据格式

首先需要了解 Drainer 写入到 Kafka 中的数据格式:

```
// Column 保存列的数据,针对数据的类型,保存在对应的变量中
message Column {
// 数据是否为 null
optional bool is_null = 1 [ default = false ];
// 保存 int 类型的数据
optional int64 int64_value = 2;
// 保存 uint、enum, set 类型的数据
optional uint64 uint64_value = 3;
// 保存 float、double 类型的数据
optional double double_value = 4;
// 保存 bit、blob、binary、json 类型的数据
optional bytes bytes_value = 5;
// 保存 date、time、decimal、text、char 类型的数据
optional string string_value = 6;
}

// ColumnInfo 保存列的信息,包括列名、类型、是否为主键
message ColumnInfo {
optional string name = 1 [ (gogoproto.nullable) = false ];
// MySQL 中小写的列字段类型
// https://dev.mysql.com/doc/refman/8.0/en/data-types.html
// numeric 类型:int bigint smallint tinyint float double decimal bit
// string 类型:text longtext mediumtext char tinytext varchar
// blob longblog mediumblog binary tinyblob varbinary
ericsyh marked this conversation as resolved.
Show resolved Hide resolved
// enum set
// json 类型:json
optional string mysql_type = 2 [ (gogoproto.nullable) = false ];
optional bool is_primary_key = 3 [ (gogoproto.nullable) = false ];
}

// Row 保存一行的具体数据
message Row { repeated Column columns = 1; }

// MutationType 表示 DML 的类型
enum MutationType {
Insert = 0;
Update = 1;
Delete = 2;
}

// Table 包含一个表的数据变更
message Table {
optional string schema_name = 1;
optional string table_name = 2;
repeated ColumnInfo column_info = 3;
repeated TableMutation mutations = 4;
}

// TableMutation 保存一行数据的变更
message TableMutation {
required MutationType type = 1;
// 修改后的数据
required Row row = 2;
// 修改前的数据,只对 Update MutationType 有效
optional Row change_row = 3;
}

// DMLData 保存一个表所有的 DML 造成的数据变更
ericsyh marked this conversation as resolved.
Show resolved Hide resolved
message DMLData {
// `tables` 包含一个表的所有数据变更
ericsyh marked this conversation as resolved.
Show resolved Hide resolved
repeated Table tables = 1;
}

// DDLData 保存 DDL 的信息
message DDLData {
// 当前使用的数据库
optional string schema_name = 1;
// 相关表
optional string table_name = 2;
// `ddl_query` 是原始的 DDL 语句 query
optional bytes ddl_query = 3;
}

// BinlogType 为 Binlog 的类型,分为 DML 和 DDL
enum BinlogType {
DML = 0; // Has `dml_data`
DDL = 1; // Has `ddl_query`
}

// Binlog 保存一个事务所有的变更,Kafka 中保存的数据为该结构数据序列化后的结果
message Binlog {
optional BinlogType type = 1 [ (gogoproto.nullable) = false ];
optional int64 commit_ts = 2 [ (gogoproto.nullable) = false ];
// dml_data 是由 DML 类型的数据序列化后生成的数据
ericsyh marked this conversation as resolved.
Show resolved Hide resolved
optional DMLData dml_data = 3;
optional DDLData ddl_data = 4;
}
```

查看数据格式的具体定义,参见 [binlog.proto](https://github.com/pingcap/tidb-tools/blob/master/tidb-binlog/slave_binlog_proto/proto/binlog.proto)。

### Driver

TiDB-Tools 项目提供了用于读取 Kafka 中 binlog 数据的 Driver,具有如下功能:
ericsyh marked this conversation as resolved.
Show resolved Hide resolved

* 读取 Kafka 的数据
* 根据 commit ts 查找到 Kafka 中存储的 binlog 的位置
ericsyh marked this conversation as resolved.
Show resolved Hide resolved

使用该 Driver 时,用户需要配置如下信息:

* KafkaAddr:Kafka 集群的地址
* CommitTS:从哪个 commit ts 开始读取 binlog
* Offset:从 Kafka 哪个 offset 开始读取,如果设置了 CommitTS 就不用配置该参数
* ClusterID:TiDB 集群的 cluster ID
ericsyh marked this conversation as resolved.
Show resolved Hide resolved

用户以包的形式引用 Driver 的代码即可使用,可以参考 Driver 中提供的的示例代码来学习如何使用 Driver 以及 binlog 数据的解析,目前提供了两个例子:
ericsyh marked this conversation as resolved.
Show resolved Hide resolved

* 使用该 Driver 将数据同步到 MySQL,该示例包含将 binlog 转化为 SQL 的具体方法
* 使用该 Driver 将数据打印出来

Driver 项目地址:[Binlog Slave Driver](https://github.com/pingcap/tidb-tools/tree/master/tidb-binlog/driver)。

> **注意:**
>
> - 示例代码仅仅用于示范如何使用 Driver,如果需要用于生产环境需要优化代码。
> - 目前仅提供了 golang 版本的 Driver 以及示例代码。如果需要使用其他语言,用户需要根据 binlog 的 proto 文件生成相应语言的代码文件,并自行开发程序读取 Kafka 中的 binlog 数据、解析数据、输出到下游。也欢迎用户优化 example 代码,以及提交其他语言的示例代码到 [TiDB-Tools](https://github.com/pingcap/tidb-tools)。
ericsyh marked this conversation as resolved.
Show resolved Hide resolved
Loading