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

reference/tidb-binlog: add docs about relay log #2224

Merged
merged 27 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0dc57be
Add docs about relay log
july2993 Feb 10, 2020
8c5893b
Merge branch 'master' into relay_doc
IANTHEREAL Feb 10, 2020
aaa1418
Address comment
july2993 Feb 10, 2020
552c3c1
Merge remote-tracking branch 'july2993/relay_doc' into relay_doc
july2993 Feb 10, 2020
e2eeafe
Apply suggestions from code review
july2993 Feb 10, 2020
fbab790
Remove trailing space
july2993 Feb 10, 2020
42cca9d
Update dev/reference/tidb-binlog/deploy.md
july2993 Feb 12, 2020
161a7ea
Add GC strategy
july2993 Feb 12, 2020
7571cdb
rename status as consistent
july2993 Feb 12, 2020
c05dccd
Merge branch 'master' into relay_doc
july2993 Feb 12, 2020
7b00bc7
refine document of binlog relay
IANTHEREAL Feb 13, 2020
973a764
add relay
IANTHEREAL Feb 13, 2020
6efa7d8
refine relay log description
IANTHEREAL Feb 13, 2020
c8c1b25
format document
IANTHEREAL Feb 13, 2020
6b51e21
Merge branch 'master' into relay_doc
IANTHEREAL Feb 13, 2020
2cf96a6
Apply suggestions from code review
july2993 Feb 17, 2020
ed58dc7
Address comment
july2993 Feb 17, 2020
d04d1c5
Merge branch 'master' into relay_doc
july2993 Feb 17, 2020
968eda6
Address comment
july2993 Feb 18, 2020
ad905b4
Merge branch 'master' into relay_doc
july2993 Feb 18, 2020
0172889
Merge branch 'master' into relay_doc
IANTHEREAL Feb 18, 2020
68cac7b
reference/tidb-binlog: fix typos, add aliases, add toc
TomShawn Feb 18, 2020
7d83c3d
Merge branch 'master' into relay_doc
july2993 Feb 19, 2020
45b561a
align other versions
july2993 Feb 19, 2020
c590bd3
Update v3.1/reference/tidb-binlog/relay-log.md
july2993 Feb 19, 2020
80f90d8
Update v3.0/reference/tidb-binlog/relay-log.md
july2993 Feb 19, 2020
60f569b
Merge branch 'master' into relay_doc
july2993 Feb 19, 2020
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: 7 additions & 0 deletions dev/reference/tidb-binlog/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,13 @@ Drainer="192.168.0.13"

# replicate-do-db = ["~^b.*","s1"]

# [syncer.relay]
# 保存 relay log 的目录,空值表示不开启。
# 只有下游是 TiDB/MySQL 配置才有意义。
# log-dir = ""
# 每个文件的最大大小
# max-file-size = 10485760

# [[syncer.replicate-do-table]]
# db-name ="test"
# tbl-name = "log"
Expand Down
2 changes: 1 addition & 1 deletion dev/reference/tidb-binlog/monitor.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: TiDB Binlog 集群监控
category: reference
aliases: ['/docs-cn/dev/how-to/monitor/tidb-binlog/','/docs-cn/dev/reference/tools/tidb-binlog/monitor/']
aliases: ['/docs-cn/dev/how-to/monitor/tidb-binlog-monitor/','/docs-cn/dev/reference/tools/tidb-binlog/monitor/']
---

# TiDB Binlog 集群监控
Expand Down
1 change: 1 addition & 0 deletions dev/reference/tidb-binlog/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ TiDB Binlog 集群主要分为 Pump 和 Drainer 两个组件,以及 binlogctl
* TiDB 通过内置的 Pump Client 将 Binlog 分发到各个 Pump。
* Pump 负责存储 Binlog,并将 Binlog 按顺序提供给 Drainer。
* Drainer 负责读取各个 Pump 的 Binlog,归并排序后发送到下游。
* Drainer 支持 [relay log](/dev/reference/tidb-binlog/relay-log.md) 功能,通过 relay log 保证下游集群的一致性状态

## 注意事项

Expand Down
55 changes: 55 additions & 0 deletions dev/reference/tidb-binlog/relay-log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: TiDB Binlog relay log
category: reference
aliases: ['/docs-cn/dev/reference/tools/tidb-binlog/relay-log/']
---

# 关于 relay log

drainer 同步 binlog 会拆分上游的事务并发写下游,在极端情况上游集群不可用并且 drainer 异常退出后,同步的下游集群(MySQL/TiDB)可能处于数据不一致的中间状态,而 drainer 借助 relay log 可以确保将下游集群同步到一个一致的状态。

## drainer 同步的状态一致性

下游集群达到一致的状态的定义为:

* 下游集群的数据等同于设置了 _tidb_snapshot = ts_ 的快照上游 TiDB 集群的数据

checkpoint 状态一致性:

drainer checkpoint 保存了一致性状态 consistent,drainer 运行时会是 `false`,正常退出后会更新为 `true`。

```
mysql> select * from tidb_binlog.checkpoint;
+---------------------+----------------------------------------------------------------+
| clusterID | checkPoint |
+---------------------+----------------------------------------------------------------+
| 6791641053252586769 | {"consistent":false,"commitTS":414529105591271429,"ts-map":{}} |
+---------------------+----------------------------------------------------------------+
```

## 原理

当 drainer 开启 relay log 后会先将 binlog event 写到磁盘上,然后再同步给下游集群。

如果上游集群不可用,drainer 可以通过读取 relay log 把下游集群恢复到一个一致的状态。

除非同时丢失 relay log 数据,不过这是概率极小的事件。此外可以使用 nfs 等网络文件系统来保证 relay log 的数据安全。

### 触发从 relay log 消费 binlog

当 drainer 启动时连接不上上游集群的 PD 并且探测到 checkpoint 的 `consistent = false` , 会尝试读取 relay log 将下游集群恢复到一个一致的状态,然后 drainer 进程将 checkpoint 的 status 设置为 0 后主动退出。

### relay log GC 机制

drainer 在运行时如果确认已经将一个 relay log 文件的全部数据都成功同步到下游了就会马上删除这个文件,所以不会占用很多空间,默认文件大小达到 10M 就会做切分,开始写新的文件。

## 配置

开启 relay log 功能只需要在 drainer 添加如下配置:

```
[syncer.relay]
# 保存 relay log 的目录,空值表示不开启。
# 只有下游是 TiDB/MySQL 配置才有意意义。
log-dir = "/dir/to/save/log"
```