Skip to content

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

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

Merged
merged 27 commits into from
Feb 19, 2020
Merged
Changes from 6 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
43 changes: 43 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 Expand Up @@ -612,6 +619,42 @@ Drainer="192.168.0.13"

如果命令行参数与配置文件中的参数重合,则使用命令行设置的参数的值。

# 关于 Relay log

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

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

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

当 drainer 开启 relay log 后会先将 binlog event 写到磁盘上,然后再同步给下游集群。如果上游集群不可用,我们总是可以通过 relay log 把集群恢复到一个一致的状态。除非同时丢失 relay log 数据,不过这是概率极小的事件。此外可以使用 nfs 等网络文件系统来保证 relay log 的数据安全。

relay log 会尽可能快的删除已经同步到下游的 binlog event,所以不会占很多磁盘空间。

下游报存的 checkpoint 可以看到 status 状态, 0 表示达到一致的状态。drainer 运行时会是 1,正常退出后会更新为 0。

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

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

## 配置

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

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

> **注意:**
>
> - 在运行 TiDB 时,需要保证至少一个 Pump 正常运行。
Expand Down