1 . Clone Plugin介绍
本地克隆:
启动克隆操作的MySQL服务器实例中的数据,克隆到同服务器或同节点上的一个目录里
image.png
远程克隆:
默认情况下,远程克隆操作会删除接受者(recipient)数据目录中的数据,并将其替换为捐赠者(donor)的克隆数据。
您也可以将数据克隆到接受者的其他目录,以避免删除现有数据。(可选)
image.png
2. 原理
# PAGE COPY
这里有两个动作
开启redo archiving功能,从当前点开始存储新增的redo log,这样从当前点开始所有的增量修改都不会丢失。同时上一步在page track的page被发送到目标端。确保当前点之前所做的变更一定发送到目标端。
关于redo archiving,实际上这是官方早就存在的功能,主要用于官方的企业级备份工具,但这里clone利用了该特性来维持增量修改产生的redo。
在开始前会做一次checkpoint, 开启一个后台线程log_archiver_thread()来做日志归档。当有新的写入时(notify_about_advanced_write_lsn)也会通知他去archive。当arch_log_sys处于活跃状态时,他会控制日志写入以避免未归档的日志被覆盖(log_writer_wait_on_archiver), 注意如果log_writer等待时间过长的话, archive任务会被中断掉.
# Redo Copy
停止Redo Archiving", 所有归档的日志被发送到目标端,这些日志包含了从page copy阶段开始到现在的所有日志,另外可能还需要记下当前的复制点,例如最后一个事务提交时的binlog位点或者gtid信息,在系统页中可以找到
# Done
目标端重启实例,通过crash recovery将redo log应用上去。
3. 限制
官方文档列出的一些限制:
The clone plugin is subject to these limitations:
* DDL, is not permitted during a cloning operation. This limitation should be considered when selecting data sources. A workaround is to use dedicated donor instances, which can accommodate DDL operations being blocked while data is cloned. Concurrent DML is permitted.
* An instance cannot be cloned from a different MySQL server version. The donor and recipient must have the same MySQL server version. For example, you cannot clone between MySQL 5.7 and MySQL 8.0\. The clone plugin is only supported in MySQL 8.0.17 and higher.
* Only a single MySQL instance can be cloned at a time. Cloning multiple MySQL instances in a single cloning operation is not supported.
* The X Protocol port specified byis not supported for remote cloning operations
* The clone plugin does not support cloning of MySQL server configurations.
* The clone plugin does not support cloning of binary logs.
* The clone plugin only clones data stored in `InnoDB`. Other storage engine data is not cloned.
* Connecting to the donor MySQL server instance through MySQL Router is not supported