Project: StarRocks (App Definition and Development / Database)
File: data_migration_tool.md

displayed_sidebar: "English" The StarRocks Cross-cluster Data Migration Tool is provided by StarRocks Community. You can use this tool to easily migrate data from the source cluster to the target cluster. :::note The StarRocks Cross-cluster Data Migration Tool only supports migrating data from a shared-nothing cluster to either another shared-nothing cluster or a shared-data cluster. The StarRocks version of the target cluster must be v3.1.8, v3.2.3, or later. ::: The following preparations must be performed on the target cluster for data migration. StarRocks may behave differently between the old and new versions, causing problems during cross-cluster data migration. Therefore, you must enable Legacy Compatibility for the target cluster before data migration and disable it after data migration is completed. You can check whether Legacy Compatibility for Replication is enabled by using the following statement: ```SQL ADMIN SHOW FRONTEND CONFIG LIKE 'enablelegacycompatibilityforreplication'; ``` If `true` is returned, it indicates that Legacy Compatibility for Replication is enabled. Dynamically enable Legacy Compatibility for Replication: ```SQL ADMIN SET FRONTEND CONFIG("enablelegacycompatibilityforreplication"="true"); ``` To prevent Legacy Compatibility for Replication from automatically disabling during the data migration process in case of cluster restart, you also need to add the following configuration item in the FE configuration file fe.conf: ```Properties enablelegacycompatibilityforreplication = true ``` After the data migration is completed, you need to remove the configuration `enablelegacycompatibilityforreplication = true` from the configuration file, and dynamically disable Legacy Compatibility for Replication using the following statement: ```SQL ADMIN SET FRONTEND CONFIG("enablelegacycompatibilityforreplication"="false"); ``` If the target cluster for data migration is a shared-data cluster, you need to manually disable Compaction before starting the data migration and re-enable it after the data migration is completed. You can check whether Compaction is enabled by using the following statement: ```SQL ADMIN SHOW FRONTEND CONFIG LIKE 'lakecompactionmax_tasks'; ``` If `0` is returned, it indicates that Compaction is disabled. Dynamically disable Compaction: ```SQL ADMIN SET FRONTEND CONFIG("lakecompactionmax_tasks"="0"); ``` To prevent Compaction from automatically enabling during the data migration process in case of cluster restart, you also need to add the following configuration item in the FE configuration file fe.conf: ```Properties lakecompactionmax_tasks = 0 ``` After the data migration is completed, you need to remove the configuration `lakecompactionmax_tasks = 0` from the configuration file, and dynamically enable Compaction using the following statement: ```SQL ADMIN SET FRONTEND CONFIG("lakecompactionmax_tasks"="-1"); ``` You can configure data migration operations using the following FE and BE parameters. In most cases, the default configuration can meet your needs. If you wish to use the default configuration, you can skip this step. :::note Please note that increasing the values of the following configuration items can accelerate migration but will also increase the load pressure on the source cluster. ::: The following FE parameters are dynamic configuration items. Refer to on how to modify them. | Parameter | Default | Unit | Description | | - | -- | -- | | | replicationmaxparalleltablecount | 100 | - | The maximum number of concurrent data synchronization tasks allowed. StarRocks creates one synchronization task for each table. | | replicationmaxparallelreplicacount| 10240 | - | The maximum number of tablet replica allowed for concurrent synchronization. | | replicationmaxparalleldatasize_mb | 1048576 | MB | The maximum size of data allowed for concurrent synchronization. | | replicationtransactiontimeout_sec | 3600 | Seconds | The timeout duration for synchronization tasks. | The following BE parameter is a dynamic configuration item. Refer to on how to modify

| Parameter | Default | Unit | Description | | - | -- | -- | | | replication_threads | 0 | - | The number of threads for executing synchronization tasks. `0` indicates setting the number of threads to the 4 times of number of CPU cores on the machine where the BE resides. | It is recommended to install the migration tool on the server where the target cluster resides. Launch a terminal, and download the binary package of the tool. ```Bash wget https://releases.starrocks.io/starrocks/starrocks-cluster-sync.tar.gz ``` Decompress the package. ```Bash tar -xvzf starrocks-cluster-sync.tar.gz ``` Navigate to the extracted folder and modify the configuration file conf/sync.properties. ```Bash cd starrocks-cluster-sync vi conf/sync.properties ``` The file content is as follows: ```Properties onetimerun_mode=false sourcefehost= sourcefequery_port=9030 sourceclusteruser=root sourceclusterpassword= sourceclustertoken= targetfehost= targetfequery_port=9030 targetclusteruser=root targetclusterpassword= includedatalist= excludedatalist= targetclusterstorage_volume= targetclusterreplication_num=-1 metajobinterval_seconds=180 metajobthreads=4 ddljobinterval_seconds=10 ddljobbatch_size=10 ddljoballowdroptarget_only=false ddljoballowdropschemachangetable=true ddljoballowdropinconsistent_partition=true replicationjobinterval_seconds=10 replicationjobbatch_size=10 ``` The description of the parameters is as follows: | Parameter | Description | | -- | | | onetimerun_mode | Whether to enable one-time synchronization mode. When one-time synchronization mode is enabled, the migration tool only performs full synchronization instead of incremental synchronization. | | sourcefehost | The IP address or FQDN (Fully Qualified Domain Name) of the source cluster's FE. | | sourcefequeryport | The query port (`queryport`) of the source cluster's FE. | | sourceclusteruser | The username used to log in to the source cluster. This user must be granted the OPERATE privilege on the SYSTEM level. | | sourceclusterpassword | The user password used to log in to the source cluster. | | sourceclustertoken | Token of the source cluster. For information on how to obtain the cluster token, refer to below. | | targetfehost | The IP address or FQDN (Fully Qualified Domain Name) of the target cluster's FE. | | targetfequeryport | The query port (`queryport`) of the target cluster's FE. | | targetclusteruser | The username used to log in to the target cluster. This user must be granted the OPERATE privilege on the SYSTEM level. | | targetclusterpassword | The user password used to log in to the target cluster. | | includedatalist | The databases and tables that need to be migrated, with multiple objects separated by commas (`,`). For example: `db1, db2.tbl2, db3`. This item takes effect prior to `excludedatalist`. If you want to migrate all databases and tables in the cluster, you do not need to configure this item. | | excludedatalist | The databases and tables that do not need to be migrated, with multiple objects separated by commas (`,`). For example: `db1, db2.tbl2, db3`. `includedatalist` takes effect prior to this item. If you want to migrate all databases and tables in the cluster, you do not need to configure this item. | | targetclusterstorage_volume | The storage volume used to store tables in the target cluster when the target cluster is a shared-data cluster. If you want to use the default storage volume, you do not need to specify this item. | | targetclusterreplication_num | The number of replicas specified when creating tables in the target cluster. If you want to use the same replica number as the source cluster, you do not need to specify this item. | | metajobinterval_seconds | The interval, in seconds, at which the migration tool retrieves metadata from the source and target clusters. You can use the default value for this item. | | metajobthreads | The number of threads used by the migration tool to obtain metadata from the source and target clusters. You can use the default value for this

| | ddljobinterval_seconds | The interval, in seconds, at which the migration tool executes DDL statements on the target cluster. You can use the default value for this item. | | ddljobbatch_size | The batch size for executing DDL statements on the target cluster. You can use the default value for this item. | | ddljoballowdroptarget_only | Whether to allow the migration tool to delete databases, tables, or partitions that exist only in the target cluster but not in the source cluster. The default is `false`, which means they will not be deleted. You can use the default value for this item. | | ddljoballowdropschemachangetable | Whether to allow the migration tool to delete tables with inconsistent schemas between the source and target clusters. The default is `true`, meaning they will be deleted. You can use the default value for this item. The migration tool will automatically synchronize the deleted tables during the migration. | | ddljoballowdropinconsistent_partition | Whether to allow the migration tool to delete partitions with inconsistent data distribution between the source and target clusters. The default is `true`, meaning they will be deleted. You can use the default value for this item. The migration tool will automatically synchronize the deleted partitions during the migration. | | replicationjobinterval_seconds | The interval, in seconds, at which the migration tool triggers data synchronization tasks. You can use the default value for this item. | | replicationjobbatch_size | The batch size at which the migration tool triggers data synchronization tasks. You can use the default value for this item. | You can obtain the cluster token either through the HTTP port of the FE or from the metadata of the FE node. Run the following command: ```Bash curl -v http://<fehost>:<fehttp_port>/check ``` `fe_host`: The IP address or FQDN (Fully Qualified Domain Name) of the cluster's FE. `fehttpport`: The HTTP port of the cluster's FE. Output: ```Plain About to connect() to xxx.xx.xxx.xx port 8030 (#0) Trying xxx.xx.xxx.xx... Connected to xxx.xx.xxx.xx (xxx.xx.xxx.xx) port 8030 (#0) GET /check HTTP/1.1 User-Agent: curl/7.29.0 Host: xxx.xx.xxx.xx:8030 Accept: / < HTTP/1.1 200 OK < content-length: 0 < cluster_id: yyyyyyyyyyy < content-type: text/html < token: wwwwwwww-xxxx-yyyy-zzzz-uuuuuuuuuu < connection: keep-alive < Connection #0 to host xxx.xx.xxx.xx left intact ``` The `token` field represents the token of the current cluster. Log in to the server where the FE node is located and run the following command: ```Bash cat fe/meta/image/VERSION | grep token ``` Output: ```Properties token=wwwwwwww-xxxx-yyyy-zzzz-uuuuuuuuuu ``` During data migration, the migration tool needs to access all FE nodes of both the source and target clusters, and the target cluster needs to access all BE and CN nodes of the source cluster. You can obtain the network addresses of these nodes by executing the following statements on the corresponding cluster: ```SQL -- Obtain the network addresses of FE nodes in a cluster. SHOW FRONTENDS; -- Obtain the network addresses of BE nodes in a cluster. SHOW BACKENDS; -- Obtain the network addresses of CN nodes in a cluster. SHOW COMPUTE NODES; ``` If these nodes use private addresses that cannot be accessed outside the cluster, such as internal network addresses within a Kubernetes cluster, you need to map these private addresses to addresses that can be accessed from outside. Navigate to the extracted folder of the tool and modify the configuration file conf/hosts.properties ```Bash cd starrocks-cluster-sync vi

``` The default content of the file is as follows, describing how network address mapping is configured: ```Properties ``` The following example performs these operations: Map the source cluster's private network addresses `192.1.1.1` and `192.1.1.2` to `10.1.1.1` and `10.1.1.2`. Map the target cluster's private network address `fe-0.starrocks.svc.cluster.local` to `10.1.2.1`. ```Properties SOURCE_192.1.1.1=10.1.1.1 SOURCE_192.1.1.2=10.1.1.2 TARGET_fe-0.starrocks.svc.cluster.local=10.1.2.1 ``` After configuring the tool, start the migration tool to initiate the data migration process. ```Bash ./bin/start.sh ``` :::note Make sure that the BE nodes of the source and target clusters can properly communicate via the network. During runtime, the migration tool regularly checks whether the data in the target cluster is lagging behind the source cluster. If there is a lag, it initiates data migration tasks. If new data is constantly loaded into the source cluster, data synchronization will continue until the data in the target cluster is consistent with that in the source cluster. You can query tables in the target cluster during migration, but do not load new data into the tables, as it may result in inconsistencies between the data in the target cluster and the source cluster. Currently, the migration tool does not forbid data loading into the target cluster during migration. Note that data migration does not automatically terminate. You need to manually check and confirm the completion of migration and then stop the migration tool. ::: You can check the migration progress through the migration tool log log/sync.INFO.log. Example: The important metrics are as follows: `Sync progress`: The progress of data migration. The migration tool regularly checks whether the data in the target cluster is lagging behind the source cluster. Therefore, a progress of 100% only means that the data synchronization is completed within the current check interval. If new data continues to be loaded into the source cluster, the progress may decrease in the next check interval. `total`: The total number of all types of jobs in this migration operation. `ddlPending`: The number of DDL jobs pending to be executed. `jobPending`: The number of pending data synchronization jobs to be executed. `sent`: The number of data synchronization jobs sent from the source cluster but not yet started. Theoretically, this value should not be too large. If the value keeps increasing, please contact our engineers. `running`: The number of data synchronization jobs that are currently running. `finished`: The number of data synchronization jobs that are finished. `failed`: The number of failed data synchronization jobs. Failed data synchronization jobs will be resent. Therefore, in most cases, you can ignore this metric. If this value is significantly large, please contact our engineers. `unknown`: The number of jobs with an unknown status. Theoretically, this value should always be `0`. If this value is not `0`, please contact our engineers. The migration tool opens a transaction for each table. You can view the status of the migration for a table by checking the status of its corresponding transaction. ```SQL SHOW PROC "/transactions/<db_name>/running"; ``` `<db_name>` is the name of the database where the table is located. You can compare the data versions of the corresponding partitions in the source and target clusters to view the migration status of that partition. ```SQL SHOW PARTITIONS FROM <table_name>; ``` `<table_name>` is the name of the table to which the partition belongs. You can compare the data volumes in the source and target clusters to view the migration status. ```SQL SHOW DATA; ``` You can compare the row counts of tables in the source and target clusters to view the migration status of each table. ```SQL SELECT TABLE_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME;