yagagagaga commented on code in PR #1314: URL: https://github.com/apache/doris-website/pull/1314#discussion_r1832743824
########## i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/data-admin/ccr/overview.md: ########## @@ -0,0 +1,666 @@ +--- +{ + "title": "跨集群数据同步", + "language": "zh-CN" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 概览 + +### CCR 是什么 + +CCR(Cross Cluster Replication) 是跨集群数据同步,能够在库/表级别将源集群的数据变更同步到目标集群,可用于在线服务的数据可用性、隔离在离线负载、建设两地三中心。 + +### 适用场景 + +CCR 通常被用于容灾备份、读写分离、集团与公司间数据传输和隔离升级等场景。 + +- 容灾备份:通常是将企业的数据备份到另一个集群与机房中,当突发事件导致业务中断或丢失时,可以从备份中恢复数据或快速进行主备切换。一般在对 SLA 要求比较高的场景中,都需要进行容灾备份,比如在金融、医疗、电子商务等领域中比较常见。 + +- 读写分离:读写分离是将数据的查询操作和写入操作进行分离,目的是降低读写操作的相互影响并提升资源的利用率。比如在数据库写入压力过大或在高并发场景中,采用读写分离可以将读/写操作分散到多个地域的只读/只写的数据库案例上,减少读写间的互相影响,有效保证数据库的性能及稳定性。 + +- 集团与分公司间数据传输:集团总部为了对集团内数据进行统一管控和分析,通常需要分布在各地域的分公司及时将数据传输同步到集团总部,避免因为数据不一致而引起的管理混乱和决策错误,有利于提高集团的管理效率和决策质量。 + +- 隔离升级:当在对系统集群升级时,有可能因为某些原因需要进行版本回滚,传统的升级模式往往会因为元数据不兼容的原因无法回滚。而使用 CCR 可以解决该问题,先构建一个备用的集群进行升级并双跑验证,用户可以依次升级各个集群,同时 CCR 也不依赖特定版本,使版本的回滚变得可行。 + +### 任务类别 + +CCR 支持两个类别的任务,分别是库级别和表级别,库级别的任务同步一个库的数据,表级别的任务只同步一个表的数据。 + +## 原理与架构 + +### 名词解释 + +源集群:源头集群,业务数据写入的集群,需要 2.0 版本 + +目标集群:跨集群同步的目标集群,需要 2.0 版本 + +binlog:源集群的变更日志,包括 schema 和数据变更 + +syncer:一个轻量级的进程 + +上游:库级别任务时指上游库,表级别任务时指上游表。 + +下游:库级别任务时指下游库,表级别人物时指下游表。 + +### 架构说明 + + + +CCR 工具主要依赖一个轻量级进程:Syncers。Syncers 会从源集群获取 binlog,直接将元数据应用于目标集群,通知目标集群从源集群拉取数据。从而实现全量和增量迁移。 + +### 同步方式 + +CCR 支持四种同步方式: + +| 同步方式 | 原理 | 触发时机 | +| Full Sync | 上游全量backup,下游restore。 | 首次同步或者操作触发,操作见功能列表。 | +| Partial Sync | 上游表或者分区级别 Backup,下游表或者分区级别restore。 | 操作触发,操作见功能列表。 | +| TXN | 增量数据同步,上游提交之后,下游开始同步。 | 操作触发,操作见功能列表。 | +| SQL | 在下游回放上游操作的 SQL。 | 操作触发,操作见功能列表。 | Review Comment: ```suggestion | 同步方式 | 原理 | 触发时机 | |--------------|------------------------------------|---------------------| | Full Sync | 上游全量backup,下游restore。 | 首次同步或者操作触发,操作见功能列表。 | | Partial Sync | 上游表或者分区级别 Backup,下游表或者分区级别restore。 | 操作触发,操作见功能列表。 | | TXN | 增量数据同步,上游提交之后,下游开始同步。 | 操作触发,操作见功能列表。 | | SQL | 在下游回放上游操作的 SQL。 | 操作触发,操作见功能列表。 | ``` ########## i18n/zh-CN/docusaurus-plugin-content-docs/current/admin-manual/data-admin/ccr/overview.md: ########## @@ -0,0 +1,666 @@ +--- +{ + "title": "跨集群数据同步", + "language": "zh-CN" +} +--- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 概览 + +### CCR 是什么 + +CCR(Cross Cluster Replication) 是跨集群数据同步,能够在库/表级别将源集群的数据变更同步到目标集群,可用于在线服务的数据可用性、隔离在离线负载、建设两地三中心。 + +### 适用场景 + +CCR 通常被用于容灾备份、读写分离、集团与公司间数据传输和隔离升级等场景。 + +- 容灾备份:通常是将企业的数据备份到另一个集群与机房中,当突发事件导致业务中断或丢失时,可以从备份中恢复数据或快速进行主备切换。一般在对 SLA 要求比较高的场景中,都需要进行容灾备份,比如在金融、医疗、电子商务等领域中比较常见。 + +- 读写分离:读写分离是将数据的查询操作和写入操作进行分离,目的是降低读写操作的相互影响并提升资源的利用率。比如在数据库写入压力过大或在高并发场景中,采用读写分离可以将读/写操作分散到多个地域的只读/只写的数据库案例上,减少读写间的互相影响,有效保证数据库的性能及稳定性。 + +- 集团与分公司间数据传输:集团总部为了对集团内数据进行统一管控和分析,通常需要分布在各地域的分公司及时将数据传输同步到集团总部,避免因为数据不一致而引起的管理混乱和决策错误,有利于提高集团的管理效率和决策质量。 + +- 隔离升级:当在对系统集群升级时,有可能因为某些原因需要进行版本回滚,传统的升级模式往往会因为元数据不兼容的原因无法回滚。而使用 CCR 可以解决该问题,先构建一个备用的集群进行升级并双跑验证,用户可以依次升级各个集群,同时 CCR 也不依赖特定版本,使版本的回滚变得可行。 + +### 任务类别 + +CCR 支持两个类别的任务,分别是库级别和表级别,库级别的任务同步一个库的数据,表级别的任务只同步一个表的数据。 + +## 原理与架构 + +### 名词解释 + +源集群:源头集群,业务数据写入的集群,需要 2.0 版本 + +目标集群:跨集群同步的目标集群,需要 2.0 版本 + +binlog:源集群的变更日志,包括 schema 和数据变更 + +syncer:一个轻量级的进程 + +上游:库级别任务时指上游库,表级别任务时指上游表。 + +下游:库级别任务时指下游库,表级别人物时指下游表。 + +### 架构说明 + + + +CCR 工具主要依赖一个轻量级进程:Syncers。Syncers 会从源集群获取 binlog,直接将元数据应用于目标集群,通知目标集群从源集群拉取数据。从而实现全量和增量迁移。 + +### 同步方式 + +CCR 支持四种同步方式: + +| 同步方式 | 原理 | 触发时机 | +| Full Sync | 上游全量backup,下游restore。 | 首次同步或者操作触发,操作见功能列表。 | +| Partial Sync | 上游表或者分区级别 Backup,下游表或者分区级别restore。 | 操作触发,操作见功能列表。 | +| TXN | 增量数据同步,上游提交之后,下游开始同步。 | 操作触发,操作见功能列表。 | +| SQL | 在下游回放上游操作的 SQL。 | 操作触发,操作见功能列表。 | + +## 使用 + +使用非常简单,只需把 Syncers 服务启动,给他发一个命令,剩下的交给 Syncers 完成就行。 + +**1. 部署源 Doris 集群** + +**2. 部署目标 Doris 集群** + +**3. 首先源集群和目标集群都需要打开 binlog,在源集群和目标集群的 fe.conf 和 be.conf 中配置如下信息:** + +```sql +enable_feature_binlog=true +``` + +**4. 部署 syncers** + +1. 构建 CCR syncer + + ```shell + git clone https://github.com/selectdb/ccr-syncer + + cd ccr-syncer + + bash build.sh <-j NUM_OF_THREAD> <--output SYNCER_OUTPUT_DIR> + + cd SYNCER_OUTPUT_DIR# 联系相关同学免费获取 ccr 二进制包 + ``` + +2. 启动和停止 syncer + + ```shell + # 启动 + cd bin && sh start_syncer.sh --daemon + + # 停止 + sh stop_syncer.sh + ``` + +**5. 打开源集群中同步库/表的 Binlog** + +```shell +-- 如果是整库同步,可以执行如下脚本,使得该库下面所有的表都要打开 binlog.enable +vim shell/enable_db_binlog.sh +修改源集群的 host、port、user、password、db +或者 ./enable_db_binlog.sh --host $host --port $port --user $user --password $password --db $db + +-- 如果是单表同步,则只需要打开 table 的 binlog.enable,在源集群上执行: +ALTER TABLE enable_binlog SET ("binlog.enable" = "true"); +``` + +**6. 向 syncer 发起同步任务** + +```shell +curl -X POST -H "Content-Type: application/json" -d '{ + "name": "ccr_test", + "src": { + "host": "localhost", + "port": "9030", + "thrift_port": "9020", + "user": "root", + "password": "", + "database": "your_db_name", + "table": "your_table_name" + }, + "dest": { + "host": "localhost", + "port": "9030", + "thrift_port": "9020", + "user": "root", + "password": "", + "database": "your_db_name", + "table": "your_table_name" + } +}' http://127.0.0.1:9190/create_ccr +``` + +同步任务的参数说明: + +```shell +name: CCR同步任务的名称,唯一即可 +host、port:对应集群 Master FE的host和mysql(jdbc) 的端口 +user、password:syncer以何种身份去开启事务、拉取数据等 +database、table: +如果是库级别的同步,则填入your_db_name,your_table_name为空 +如果是表级别同步,则需要填入your_db_name,your_table_name +向syncer发起同步任务中的name只能使用一次 +``` + +## Syncer 详细操作手册 + +### 启动 Syncer 说明 + +根据配置选项启动 Syncer,并且在默认或指定路径下保存一个 pid 文件,pid 文件的命名方式为`host_port.pid`。 + +**输出路径下的文件结构** + +在编译完成后的输出路径下,文件结构大致如下所示: + +```sql +output_dir + bin + ccr_syncer + enable_db_binlog.sh + start_syncer.sh + stop_syncer.sh + db + [ccr.db] # 默认配置下运行后生成 + log + [ccr_syncer.log] # 默认配置下运行后生成 +``` + +:::caution +**后文中的 start_syncer.sh 指的是该路径下的 start_syncer.sh!!!** +::: + +**启动选项** + +1. --daemon + +后台运行 Syncer,默认为 false + +```sql +bash bin/start_syncer.sh --daemon +``` + +2. --db_type + +Syncer 目前能够使用两种数据库来保存自身的元数据,分别为`sqlite3`(对应本地存储)和`mysql`(本地或远端存储) + +```sql +bash bin/start_syncer.sh --db_type mysql +``` + +默认值为 sqlite3 + +在使用 mysql 存储元数据时,Syncer 会使用`CREATE IF NOT EXISTS`来创建一个名为`ccr`的库,ccr 相关的元数据表都会保存在其中 + +3. --db_dir + +**这个选项仅在 db 使用****`sqlite3`****时生效** + +可以通过此选项来指定 sqlite3 生成的 db 文件名及路径。 + +```sql +bash bin/start_syncer.sh --db_dir /path/to/ccr.db +``` + +默认路径为`SYNCER_OUTPUT_DIR/db`,文件名为`ccr.db` + +4. --db_host & db_port & db_user & db_password + +**这个选项仅在 db 使用****`mysql`****时生效** + +```sql +bash bin/start_syncer.sh --db_host 127.0.0.1 --db_port 3306 --db_user root --db_password "qwe123456" +``` + +db_host、db_port 的默认值如例子中所示,db_user、db_password 默认值为空 + +5. --log_dir + +日志的输出路径 + +```sql +bash bin/start_syncer.sh --log_dir /path/to/ccr_syncer.log +``` + +默认路径为`SYNCER_OUTPUT_DIR/log`,文件名为`ccr_syncer.log` + +6. --log_level + +用于指定 Syncer 日志的输出等级。 + +```sql +bash bin/start_syncer.sh --log_level info +``` + +日志的格式如下,其中 hook 只会在`log_level > info`的时候打印: + +```sql +# time level msg hooks +[2023-07-18 16:30:18] TRACE This is trace type. ccrName=xxx line=xxx +[2023-07-18 16:30:18] DEBUG This is debug type. ccrName=xxx line=xxx +[2023-07-18 16:30:18] INFO This is info type. ccrName=xxx line=xxx +[2023-07-18 16:30:18] WARN This is warn type. ccrName=xxx line=xxx +[2023-07-18 16:30:18] ERROR This is error type. ccrName=xxx line=xxx +[2023-07-18 16:30:18] FATAL This is fatal type. ccrName=xxx line=xxx +``` + +在--daemon 下,log_level 默认值为`info` + +在前台运行时,log_level 默认值为`trace`,同时日志会通过 tee 来保存到 log_dir + +6. --host && --port + +用于指定 Syncer 的 host 和 port,其中 host 只起到在集群中的区分自身的作用,可以理解为 Syncer 的 name,集群中 Syncer 的名称为`host:port` + +```sql +bash bin/start_syncer.sh --host 127.0.0.1 --port 9190 +``` + +host 默认值为 127.0.0.1,port 的默认值为 9190 + +7. --pid_dir + +用于指定 pid 文件的保存路径 + +pid 文件是 stop_syncer.sh 脚本用于关闭 Syncer 的凭据,里面保存了对应 Syncer 的进程号,为了方便 Syncer 的集群化管理,可以指定 pid 文件的保存路径 + +```sql +bash bin/start_syncer.sh --pid_dir /path/to/pids +``` + +默认值为`SYNCER_OUTPUT_DIR/bin` + +### Syncer 停止说明 + +根据默认或指定路径下 pid 文件中的进程号关闭对应 Syncer,pid 文件的命名方式为`host_port.pid`。 + +**输出路径下的文件结构** + +在编译完成后的输出路径下,文件结构大致如下所示: + +```shell +output_dir + bin + ccr_syncer + enable_db_binlog.sh + start_syncer.sh + stop_syncer.sh + db + [ccr.db] # 默认配置下运行后生成 + log + [ccr_syncer.log] # 默认配置下运行后生成 +``` +:::caution +**后文中的 stop_syncer.sh 指的是该路径下的 stop_syncer.sh!!!** +::: + +**停止选项** + +有三种关闭方法: + +1. 关闭目录下单个 Syncer + + 指定要关闭 Syncer 的 host && port,注意要与 start_syncer 时指定的 host 一致 + +2. 批量关闭目录下指定 Syncer + + 指定要关闭的 pid 文件名,以空格分隔,用`" "`包裹 + +3. 关闭目录下所有 Syncer + + 默认即可 + +1. --pid_dir + +指定 pid 文件所在目录,上述三种关闭方法都依赖于 pid 文件的所在目录执行 + +```shell +bash bin/stop_syncer.sh --pid_dir /path/to/pids +``` + +例子中的执行效果就是关闭`/path/to/pids`下所有 pid 文件对应的 Syncers(**方法 3**),`--pid_dir`可与上面三种关闭方法组合使用。 + +默认值为`SYNCER_OUTPUT_DIR/bin` + +2. --host && --port + +关闭 pid_dir 路径下 host:port 对应的 Syncer + +```shell +bash bin/stop_syncer.sh --host 127.0.0.1 --port 9190 +``` + +host 的默认值为 127.0.0.1,port 默认值为空 + +即,单独指定 host 时**方法 1**不生效,会退化为**方法 3**。 + +host 与 port 都不为空时**方法 1**才能生效 + +3. --files + +关闭 pid_dir 路径下指定 pid 文件名对应的 Syncer + +```shell +bash bin/stop_syncer.sh --files "127.0.0.1_9190.pid 127.0.0.1_9191.pid" +``` + +文件之间用空格分隔,整体需要用`" "`包裹住 + +### Syncer 操作列表 + +**请求的通用模板** + +```shell +curl -X POST -H "Content-Type: application/json" -d {json_body} http://ccr_syncer_host:ccr_syncer_port/operator +``` + +json_body: 以 json 的格式发送操作所需信息 + +operator:对应 Syncer 的不同操作 + +所以接口返回都是 json, 如果成功则是其中 success 字段为 true, 类似,错误的时候,是 false,然后存在`ErrMsgs`字段 + +```JSON +{"success":true} + +or + +{"success":false,"error_msg":"job ccr_test not exist"} +``` + +### operators + +- create_ccr + + 创建 CCR 任务 + + ```shell + curl -X POST -H "Content-Type: application/json" -d '{ + "name": "ccr_test", + "src": { + "host": "localhost", + "port": "9030", + "thrift_port": "9020", + "user": "root", + "password": "", + "database": "demo", + "table": "example_tbl" + }, + "dest": { + "host": "localhost", + "port": "9030", + "thrift_port": "9020", + "user": "root", + "password": "", + "database": "ccrt", + "table": "copy" + } + }' http://127.0.0.1:9190/create_ccr + ``` + +- name: CCR 同步任务的名称,唯一即可 + +- host、port:对应集群 master 的 host 和 mysql(jdbc) 的端口 + +- thrift_port:对应 FE 的 rpc_port + +- user、password:syncer 以何种身份去开启事务、拉取数据等 + +- database、table: + + - 如果是 库级别的同步,则填入 dbName,tableName 为空 + + - 如果是表级别同步,则需要填入 dbName、tableName + +- get_lag + + 查看同步进度 Review Comment: ```suggestion 查看同步进度 ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org