跨集群数据迁移工具
StarRocks 跨集群数据迁移工具是社区提供的 StarRocks 数据迁移工具。您可以使用该工具将数据从源集群一键式迁移到目标集群。
备注
- StarRocks 跨集群数据迁移工具仅支持从存算一体集群迁移数据到存算一体集群或者存算分离集群。
- 数据迁移的目标集群必须为 v3.1.8 或 v3.2.3 及以上版本。
准备工作
以下准备工作需要在数据迁移的目标集群中进行。
开放端口
如果您开启了防火墙,则需要开通以下端口:
| 组件 | 端口 | 默认端口 |
|---|---|---|
| FE | query_port | 9030 |
| FE | http_port | 8030 |
| FE | rpc_port | 9020 |
| BE | be_http_port | 8040 |
| BE | be_port | 9060 |
开启迁移旧版本兼容
新旧版本的集群间可能存在行为差异,从而导致跨集群数据迁移时出现问题。因此在数据迁移前,您需要为目标集群开启旧版本兼容,并在数据迁移完成后关闭。
-
您可以通过以下语句查看当前集群是否开启旧版本兼容:
ADMIN SHOW FRONTEND CONFIG LIKE 'enable_legacy_compatibility_for_replication';如果返回值为
true则表示已经开启旧版本兼容。 -
动态开启旧版本兼容:
ADMIN SET FRONTEND CONFIG("enable_legacy_compatibility_for_replication"="true"); -
为防止数据迁移过程中集群重启后旧版本兼容自动关闭,您还需要在 FE 配置文件 fe.conf 中添加以下配置项:
enable_legacy_compatibility_for_replication = true
数据迁移完成后,您需要删除配置文件中的 enable_legacy_compatibility_for_replication = true,并通过以下语句动态关闭旧版本兼容:
ADMIN SET FRONTEND CONFIG("enable_legacy_compatibility_for_replication"="false");
配置数据迁移(可选)
您可以通过以下 FE 和 BE 参数配置数据迁移操作。通常情况下,默认配置即可满足需求。如果您想保留默认配置,可以选择跳过该步骤。
备注
请注意,增大以下配置项可以加速迁移,但同样会增加源集群负载压力。
FE 参数
以下 FE 参数为动态参数。修改方式请参考 配置 FE 动态参数。
| 参数名 | 默认值 | 单位 | 描述 |
|---|---|---|---|
| replication_max_parallel_table_count | 100 | - | 允许并发执行的数据同步任务数。StarRocks 为一张表创建一个同步任务。 |
| replication_max_parallel_replica_count | 10240 | - | 允许并发同步的 tablet 副本数。 |
| replication_max_parallel_data_size_mb | 1048576 | MB | 允许并发同步的数据量。 |
| replication_transaction_timeout_sec | 86400 | 秒 | 同步任务的超时时间。 |
BE 参数
以下 BE 参数为动态参数。修改方式请参考 配置 BE 动态参数。
| 参数名 | 默认值 | 单位 | 描述 |
|---|---|---|---|
| replication_threads | 0 | - | 执行同步任务的线程数。0 表示设置线程数为 BE 所在机器的 CPU 核数的 4 倍。 |
第一步:安装工具
推荐您在数据迁移目标集群所在的服务器上安装迁移工具。
-
打开终端,下载工具安装包。
wget https://releases.starrocks.io/starrocks/starrocks-cluster-sync.tar.gz -
解压安装包。
tar -xvzf starrocks-cluster-sync.tar.gz
第二步:配置工具
迁移相关的配置
进入解压后的文件夹,并修改配置文件 conf/sync.properties。
cd starrocks-cluster-sync
vi conf/sync.properties
文件内容如下:
# If true, all tables will be synchronized only once, and the program will exit automatically after completion.
one_time_run_mode=false
source_fe_host=
source_fe_query_port=9030
source_cluster_user=root
source_cluster_password=
source_cluster_password_secret_key=
source_cluster_token=
target_fe_host=
target_fe_query_port=9030
target_cluster_user=root
target_cluster_password=
target_cluster_password_secret_key=
jdbc_connect_timeout_ms=30000
jdbc_socket_timeout_ms=60000
# Comma-separated list of database names or table names like <db_name> or <db_name.table_name>
# example: db1,db2.tbl2,db3
# Effective order: 1. include 2. exclude
include_data_list=
exclude_data_list=
# If there are no special requirements, please maintain the default values for the following configurations.
target_cluster_storage_volume=
target_cluster_replication_num=-1
target_cluster_max_disk_used_percent=80
# To maintain consistency with the source cluster, use null.
target_cluster_enable_persistent_index=
max_replication_data_size_per_job_in_gb=1024
meta_job_interval_seconds=180
meta_job_threads=4
ddl_job_interval_seconds=10
ddl_job_batch_size=10
# table config
ddl_job_allow_drop_target_only=false
ddl_job_allow_drop_schema_change_table=true
ddl_job_allow_drop_inconsistent_partition=true
ddl_job_allow_drop_inconsistent_time_partition = true
ddl_job_allow_drop_partition_target_only=true
# index config
enable_bitmap_index_sync=false
ddl_job_allow_drop_inconsistent_bitmap_index=true
ddl_job_allow_drop_bitmap_index_target_only=true
# MV config
enable_materialized_view_sync=false
ddl_job_allow_drop_inconsistent_materialized_view=true
ddl_job_allow_drop_materialized_view_target_only=false
# View config
enable_view_sync=false
ddl_job_allow_drop_inconsistent_view=true
ddl_job_allow_drop_view_target_only=false
replication_job_interval_seconds=10
replication_job_batch_size=10
report_interval_seconds=300
enable_table_property_sync=false
参数说明如下:
| 参数名 | 描述 |
|---|---|
| one_time_run_mode | 是否开启一次性同步模式。开启一次性同步模式后,迁移工具只进行全量同步,不进行增量同步。 |
| source_fe_host | 源集群 FE 的 IP 地址或 FQDN。 |
| source_fe_query_port | 源集群 FE 的查询端口(query_port)。 |
| source_cluster_user | 用于登录源集群的用户名。此用户需要有 SYSTEM 级 OPERATE 权限。 |
| source_cluster_password | 用于登录源集群的用户密码。 |
| source_cluster_password_secret_key | 用于对源集群登录用户密码加密的密钥。默认值为空,代表不对登录密码进行加密。如果需要对 source_cluster_password 加密,可以通过 SQL 语句 SELECT TO_BASE64(AES_ENCRYPT('<source_cluster_password>','<source_cluster_password_secret_key>')) 获得加密后的 source_cluster_password。 |
| source_cluster_token | 源集群的 Token。关于如何获取集群 Token,见以下获取集群 Token部分。 |
| target_fe_host | 目标集群 FE 的 IP 地址或 FQDN。 |
| target_fe_query_port | 目标集群 FE 的查询端口(query_port)。 |
| target_cluster_user | 用于登录目标集群的用户名。此用户需要有 SYSTEM 级 OPERATE 权限。 |
| target_cluster_password | 用于登录目标集群的用户密码。 |
| target_cluster_password_secret_key |