- Generate statements to create tables in the database based on information of the source database and the target cluster.
- Generate SQL statements that can be executed in Flink’s SQL client to submit Flink jobs for synchronizing data, which simplifies full or incremental data synchronization in the pipeline. Currently, SMT supports the following source databases:
Download link: https://cdn-thirdparty.starrocks.com/smt.tar.gz?r=2
What SMT does and does not do
SMT generates SQL files and then exits. It reads the table definitions in your source database and writes two kinds of files to theresult directory:
starrocks-create.*.sql: CREATE TABLE statements, which you run in the database.flink-create.*.sql: Flink SQL that defines a source table and a sink table and submits anINSERT INTO ... SELECTjob, which you run in the Flink SQL client.
Synchronize data without SMT
SMT is optional. Instead, you can:- Use a Flink CDC pipeline. A pipeline is defined in a single YAML file, creates the tables itself, and runs the synchronization. See Realtime synchronization from PostgreSQL, or for MySQL, Streaming ELT from MySQL to StarRocks in the Flink CDC documentation.
- Create the tables yourself, and write the Flink SQL with the Flink connector for the database as the sink. This works for any source that Flink can read.
Steps to use SMT
The generally involved steps are as follows:- Configure the conf/config_prod.conf file.
- Execute starrocks-migration-tool.
- After execution, the SQL scripts are generated in the result directory by default. You can then use the SQL scripts in the result directory for metadata or data synchronization.
Configurations of SMT
-
[db]: information to connect the data source. Configure the information to connect the data source corresponding to the database type specified in thetypepatameter. -
[other]: additional configurations. It is recommended to specify the actual number of BE nodes in thebe_numpatameter. -
flink.starrocks.sink.*: configurations of flink-connector-starrocks. For detailed configurations and description, see configuration description. -
[table-rule.1]: rule to match tables in the data source. The CREATE TABLE statement is generated based on the regular expressions configured in the rule to match the names of databases and tables in data source. Multiple rules can be configured, and each rule generates a corresponding result file, for example:[table-rule.1]->result/starrocks-create.1.sql[table-rule.2]->result/starrocks-create.2.sql
-
A separate rule can be configured for a large table that is split into shards in databases. For example, suppose that the two databases
edu_db_1andedu_db_2contain the tablescourse_1andcourse_2respectively, and these two tables have the same structure. You can use the following rule to load data from these two tables into one table for analysis.This rule will automatically form a many-to-one loading relationship. The default name of the table that will be generated in the database iscourse__auto_shard, and you can also modify the table name in the related SOL script, such asresult/starrocks-create.3.sql.
Synchronize MySQL to the database
Introduction
Flink CDC connector and SMT can synchronize data from MySQL within subsecond.
Steps
- Download Flink. Flink 1.11 or later is supported.
-
Download Flink CDC connector. Make sure that you download the
flink-sql-connector-mysql-cdc-xxx.jarcorresponding to the version of Flink. - Download Flink-connector-starrocks.
- Copy flink-sql-connector-mysql-cdc-xxx.jar and flink-connector-starrocks-xxx.jar to flink-xxx/lib/.
- Download smt.tar.gz.
-
Extract and modify the configuration file of SMT.
-
Execute starrocks-migrate-tool. All SQL scripts are generated in the result directory.
-
Use a SQL script whose prefix is starrocks-create to generate the table in the database.
-
Use a SQL script whose prefix is flink-create to generate the Flink source and sink tables, and start a Flink job to synchronize data.
After the above command is successfully executed, the Flink job to synchronize data keeps running.
-
Observe the status of the Flink job.
If the job execution encounters an error, you can view detailed error information in the Flink logs. Also, you can modify the Flink configurations in the file conf/flink-conf.yaml, such as memory and slot.
Notes
-
How to enable MySQL binlog?
-
Modify /etc/my.cnf:
-
Restart mysqld. You can check whether MySQL binlog is enabled by executing
SHOW VARIABLES LIKE 'log_bin';.
-
Modify /etc/my.cnf:
Synchronize PostgreSQL to the database
Tip With Flink CDC 3.5 or later, a Flink CDC pipeline can synchronize PostgreSQL to the database without SMT, and creates the tables itself. For a step-by-step guide, see Realtime synchronization from PostgreSQL.Introduction
Flink CDC connector and SMT can synchronize data from PostgreSQL within subsecond. SMT can automatically generate CREATE TABLE statements of the Flink’s source and sink tables based on the cluster information and table structure of PostgreSQL and the database. Flink CDC connector reads the WAL of PostgreSQL and Flink-connector-starrocks writes data to the database .Steps
- Download Flink. The version of Flink is supported to be 1.11 or later.
- Download Flink CDC connector. Make sure that you download the flink-sql-connector-postgres-cdc-xxx.jar corresponding to the version of Flink.
- Download Flink StarRocks connector.
- Copy flink-sql-connector-postgres-cdc-xxx.jar and flink-connector-starrocks-xxx.jar to flink-xxx/lib/.
- Download smt.tar.gz.
-
Extract and modify the configuration file of SMT.
-
Execute starrocks-migrate-tool. All SQL scripts are generated in the result directory.
-
Use a SQL script whose prefix is starrocks-create to generate the table in the database.
-
Use a SQL script whose prefix is flink-create to generate the Flink source and sink tables, and start a Flink job to synchronize data.
After the above command is successfully executed, the Flink job to synchronize data keeps running.
-
Observe the status of the Flink job.
If the job execution encounters an error, you can view detailed error information in the Flink logs. Also, you can modify the Flink configurations in the file conf/flink-conf.yaml, such as memory and slot.
Notes
-
For PostgreSQL
v9.*, a special flink-cdc configuration as shown below is required (It is recommended to use PostgreSQLv10.*or later. Otherwise, you need to install WAL decoding plugins): -
How to enable PostgreSQL WAL?
Specify replica identity FULL for the tables that need to be synchronized.After making these changes, restart PostgreSQL .
Synchronize Oracle to the database
Introduction
Flink CDC connector and SMT can synchronize data from Oracle within subsecond. SMT can automatically generate CREATE TABLE statements of the Flink’s source and sink tables based on the cluster information and table structure of Oracle and the database. Flink CDC connector reads the logminer of Oracle and Flink-connector-starrocks writes data to the database.Steps
- Download Flink. The version of Flink is supported to be 1.11 or later.
- Download Flink CDC connector. Make sure that you download the flink-sql-connector-oracle-cdc-xxx.jar corresponding to the Flink version.
- Download Flink StarRocks connector.
-
Copy
flink-sql-connector-oracle-cdc-xxx.jarandflink-connector-starrocks-xxx.jartoflink-xxx/lib/. - Download smt.tar.gz.
-
Extract and modify the configuration file of SMT.
-
Execute starrocks-migrate-tool. All SQL scripts are generated in the result directory.
-
Use a SQL script whose prefix is starrocks-create to generate the table in the database.
-
Use a SQL script whose prefix is flink-create to generate the Flink source and sink tables, and start a Flink job to synchronize data.
After the above command is successfully executed, the Flink job to synchronize data keeps running.
-
Observe the status of the Flink job.
If the job execution encounters an error, you can view detailed error information in the Flink logs. Also, you can modify the Flink configurations in the file conf/flink-conf.yaml, such as memory and slot.
Notes
-
Synchronize Oracle using logminer:
- The database configurations in the [table-rule.1] does not support regular expression, so the complete database names need to be specified.
-
Because Oracle12c supports CDB mode, SMT internally automatically determines whether CDB is enabled and modifies the flink-cdc configuration correspondingly. However, users need to pay attention to whether the c## prefix needs to be added to the configuration of
[db].userto avoid issues of insufficient permission.
Synchronize Hive to the database
Introduction
This guide explains how to use SMT to synchronize Hive data to the database. During synchronization, a Duplicate table in the database is created and a Flink job keeps running to synchronize data.Steps
Preparations
- nosasl, zk: do not need to specify the
userandpassword. - none, none_http, ldap: specify the
userandpassword. - kerberos, kerberos_http: perform the following steps:
- Execute
kadmin.localon the Hive cluster and checklist_principalsto find the corresponding principal name. For example when the principal name ishive/emr-header-1.cluster-49148@EMR.49148.COM, the user needs to be set ashive/emr-header-1.cluster-49148, and the password is left empty. - Execute
kinit -kt /path/to/keytab principalon the machine where SMT is executed and executeklistto see if the correct token is generated.
- Execute
Data synchronization
- Execute starrocks-migrate-tool.
-
Use a SQL script whose prefix is starrocks-create to generate the table in the database.
-
In flink/conf/, create and edit the file sql-client-defaults.yaml:
-
Download the dependency package (flink-sql-connector-hive-xxxx) from the Hive page of the corresponding version of Flink and place it in the
flink/libdirectory. -
Start the Flink cluster and execute
flink/bin/sql-client.sh embedded < result/flink-create.all.sqlto start data synchronization.
Synchronize SQL Server to the database
Introduction
Flink CDC connector and SMT can synchronize data from SQL Server within subsecond. SMT can automatically generate CREATE TABLE statements of the Flink’s source and sink tables based on the cluster information and table structure of SQL Server and the database. Flink CDC connector captures and records row-level changes that occur in the SQL Server database server. The principle is to use the CDC feature provided by SQL Server itself. The CDC capability of SQL Server itself can archive specified changes in the database to specified change tables. The SQL Server CDC connector first reads historical data from the table using JDBC, and then fetches incremental changes from the change tables, thereby achieving full incremental synchronization. Then, Flink-connector-starrocks writes data to the database.Steps
- Download Flink. The version of Flink is supported to be 1.11 or later.
- Download Flink CDC connector. Make sure that you download the flink-sql-connector-sqlserver-cdc-xxx.jar corresponding to the Flink version.
- Download Flink StarRocks connector.
- Copy flink-sql-connector-sqlserver-cdc-xxx.jar, flink-connector-starrocks-xxx.jar to flink-xxx/lib/.
- Download smt.tar.gz.
-
Extract and modify the configuration file of SMT.
-
Execute starrocks-migrate-tool. All SQL scripts are generated in the
resultdirectory.
-
Use a SQL script whose prefix is
flink-createto generate the Flink source and sink tables, and start a Flink job to synchronize data.After the above command is successfully executed, the Flink job to synchronize data keeps running. -
Observe the status of the Flink job.
If the job execution encounters an error, you can view detailed error information in the Flink logs. Also, you can modify the Flink configurations in the file conf/flink-conf.yaml, such as memory and slot.
Notes
-
Make sure that the Server Agent Service is enabled.
Check if the Server Agent Service is running normally.
Enable the Server Agent Service.
-
Make sure that CDC for the corresponding database is enabled.
Check if CDC for the corresponding database is enabled.
Enable CDC. :::note When executing this command, make sure that the user
serverRoleissysadmin. ::: -
Make sure that CDC for the corresponding table is enabled.
Synchronize TiDB to the database
Introduction
Flink CDC connector and SMT can synchronize data from TiDB within subsecond. SMT can automatically generate DDL statements for the Flink’s source tables and sink tables based on the cluster information and table structure of TiDB and the database. The Flink CDC connector captures data by directly reading full and incremental data from the underlying TiKV storage. The full data is obtained from ranges partitioned based on keys, and the incremental data is obtained by using the CDC Client provided by TiDB. Subsequently, the data is written to the database through Flink-connector-starrocks.Steps
- Download Flink. The version of Flink is supported to be 1.11 or later.
- Download Flink CDC connector. Make sure that you download the flink-sql-connector-tidb-cdc-xxx.jar corresponding to the Flink version.
- Download Flink StarRocks connector.
- Copy flink-sql-connector-tidb-cdc-xxx.jar, flink-connector-starrocks-xxx.jar to flink-xxx/lib/.
- Download smt.tar.gz.
-
Extract and modify the configuration file of SMT.
-
Execute starrocks-migrate-tool*. All SQL scripts are generated in the
resultdirectory. -
Use a SQL script whose prefix is
starrocks-createto generate the table in the database. -
Use a SQL script whose prefix is
flink-createto generate the Flink source and sink tables, and start a Flink job to synchronize data.
-
Observe the status of the Flink job.
If the job execution encounters an error, you can view detailed error information in the Flink logs. Also, you can modify the Flink configurations in the file conf/flink-conf.yaml, such as memory and slot.
Notes
For TiDB whose version is before v4.0.0, additional configuration offlink.cdc.pd-addresses is required.