Logo
Data Migration

Data Migration #

SyntaxDescriptionType
ALTER MIGRATION RULEModify data migration ruleRAL
SHOW MIGRATION RULEView data migration ruleRAL
SHOW MIGRATION LISTModify data migration rule listRAL
SHOW MIGRATION STATUS jobIdModify data migration job statusRAL
MIGRATE TABLE x INTO yStart migration jobRAL
START MIGRATION jobIdStart stopped migration jobRAL
STOP MIGRATION jobIdStop migration jobRAL
SHOW MIGRATION CHECK ALGORITHMSView data migration consistency check algorithmRAL
CHECK MIGRATION jobIdCheck job data consistencyRAL
START MIGRATION CHECK jobIdStart the stopped data consistency check jobRAL
STOP MIGRATION CHECK jobIdStop data consistency check jobRAL
SHOW MIGRATION CHECK STATUS jobIdView data consistency check job statusRAL
COMMIT MIGRATION jobIdCommit jobRAL
ROLLBACK MIGRATION jobIdRollback job. Note: This statement will clean up the target table, please operate with cautionRAL
REGISTER MIGRATION SOURCE STORAGE UNITRegister data migration task storage unitRAL

1. Modify data migration rule #

ALTER MIGRATION RULE ();

Config Description

ALTER MIGRATION RULE (
READ( -- Data reading configuration. If it is not configured, part of the parameters will take effect by default.
  WORKER_THREAD=20, -- Obtain the thread pool size of all the data from the source side. If it is not configured, the default value is used.
  BATCH_SIZE=1000, -- The maximum number of records returned by a query operation. If it is not configured, the default value is used.
  SHARDING_SIZE=10000000, -- Sharding size of all the data. If it is not configured, the default value is used.
  RATE_LIMITER ( -- Traffic limit algorithm. If it is not configured, traffic is not limited.
  TYPE( -- Algorithm type. Option: QPS
  NAME='QPS',
  PROPERTIES( -- Algorithm property
  'qps'='500'
  )))
),
WRITE( -- Data writing configuration. If it is not configured, part of the parameters will take effect by default.
  WORKER_THREAD=20, -- The size of the thread pool on which data is written into the target side. If it is not configured, the default value is used.
  BATCH_SIZE=1000, -- The maximum number of records for a batch write operation. If it is not configured, the default value is used.
  RATE_LIMITER ( -- Traffic limit algorithm. If it is not configured, traffic is not limited.
  TYPE( -- Algorithm type. Option: TPS
  NAME='TPS',
  PROPERTIES( -- Algorithm property.
  'tps'='2000'
  )))
),
STREAM_CHANNEL ( -- Data channel. It connects producers and consumers, used for reading and writing procedures. If it is not configured, the MEMORY type is used by default.
TYPE( -- Algorithm type. Option: MEMORY
NAME='MEMORY',
PROPERTIES( -- Algorithm property
'block-queue-size'='2000' -- Property: blocking queue size.
)))
);

Default configuration

+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+ 
| read | write | stream_channel | 
+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+ 
| {"workerThread":40,"batchSize":1000,"shardingSize":10000000} | {"workerThread":40,"batchSize":1000} | {"type":"MEMORY", "props":{"block‑queue‑size":10000}} |
 +‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑+

Example

ALTER MIGRATION RULE (READ(RATE_LIMITER (TYPE(NAME='QPS’,PROPERTIES(‘qps'='5000’)))))

2. View Data Migration Rule #

SHOW MIGRATION RULE

Parameter Description

None

Example

SHOW MIGRATION RULE;

Output Description

ColumnDescription
readData reading configuration. If it is not configured, part of the parameters will take effect by default.
writeData writing configuration. If it is not configured, part of the parameters will take effect by default.
stream_channelData channel. It connects producers and consumers, used for reading and writing procedures. If it is not configured, the MEMORY type is used by default.

3. Modify Data Migration Rule List #

SHOW MIGRATION LIST;

Parameter Description

None

Example

+-------------------------------------+---------+----------------------+--------+---------------------+-----------+
| id                                  | tables  | sharding_total_count | active | create_time         | stop_time |
+-------------------------------------+---------+----------------------+--------+---------------------+-----------+
|j01016e501b498ed1bdb2c373a2e85e2529a6| t_order | 1                    | true   | 2022-08-22 16:37:01 | NULL      |
+-------------------------------------+---------+----------------------+--------+---------------------+-----------+

Output Description

ColumnDescription
IdMigration job id
tablesThe name of the table being migrated
activeWhether the task is active true or false
create_timejob create time
stop_timeJob stop time, NULL means the job is not stopped

4. View Data Migration Job Status #

SHOW MIGRATION STATUS jobId;

Parameter Description

NameDescription
jobIdData migration job id

Example

SHOW MIGRATION STATUS 'j01016e501b498ed1bdb2c373a2e85e2529a6';
+------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
| item | data_source | status                   | active | processed_records_count | inventory_finished_percentage | incremental_idle_seconds | error_message |
+------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
| 0    | ds_0        | EXECUTE_INCREMENTAL_TASK | true   | 6                       | 100                           | 81                       |               |
+------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+

Output Description

ColumnDescription
itemSequence number within the migration job
data_sourceData storage unit name
statusJob status, please refer to the status description for details
activewhether the task is active true or false
processed_records_countNumber of processed record
inventory_finished_percentageFull data processing completion progress (percentage)
incremental_idle_secondsInactive time of the incremental synchronization job (unit: second)
error_messageError message

Status Description

ValueDescription
PREPARINGPreparing
RUNNINGRunning
EXECUTE_INVENTORY_TASKFull migration
EXECUTE_INCREMENTAL_TASKIncremental migration
FINISHEDCompleted (the entire process is complete and the new rules are in effect)
PREPARING_FAILUREPreparation phase failed
EXECUTE_INVENTORY_TASK_FAILUREFull migration phase failed
EXECUTE_INCREMENTAL_TASK_FAILUREIncremental migration phase failed

5. Start Data Migration #

MIGRATE TABLE schema_name.table_name INTO schema_name.table_name;

Example

The storage node is MySQL starts data migration

MIGRATE TABLE ds_0.t_order INTO t_order;

The storage node is MySQL or other specified target logical database

MIGRATE TABLE ds_0.t_order INTO sharding_db.t_order;

Migrate multiple tables at the same time, separate multiple tables with commas

MIGRATE TABLE ds_0.t_order INTO sharding_db.t_order,ds_0.t_order1 INTO sharding_db.t_order1,ds_0.t_order2 INTO sharding_db.t_order2;

6. Start Stopped Job #

START MIGRATION jobId

Parameter Description

NameDescription
jobIdJob id

Example

Start stopped job with the specified job id

START MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6';

7. Stop Migration Job #

STOP MIGRATION jobId

Parameter Description

NameDescription
jobIdJob id

Example

Start stopped job with the specified job id

STOP MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6';

8. View data consistency algorithm #

For consistency check algorithm selection, please refer to Data Consistency Check Algorithm

SHOW MIGRATION CHECK ALGORITHMS;

Example

SHOW MIGRATION CHECK ALGORITHMS;
+----------------------------+---------------------------------------------+-----------------------------------------------------------------------------------------------+----------------------------------------------+
| type                       | type_aliases                                | supported_database_types                                                                      | description                                  |
+----------------------------+---------------------------------------------+-----------------------------------------------------------------------------------------------+----------------------------------------------+
| CRC32_MATCH                |                                             | MySQL,MariaDB,H2,Aurora                                                                       | Match CRC32 of records.                      |
| DATA_MATCH                 |                                             | SQL92,MySQL,PostgreSQL,openGauss,Oracle,SQLServer,MariaDB,H2,Hive,Presto,Aurora,DM,KingbaseES | Match raw data of records.                   |
| SphereEx:BATCH_CRC32_MATCH | SphereEx:DATA_CONSISTENCY_CHECK_CRC32_MATCH | MySQL,MariaDB,H2,Aurora                                                                       | Match CRC32 of records (Commercial edition). |
| SphereEx:DATA_DIFF         |                                             | SQL92,MySQL,PostgreSQL,openGauss,Oracle,SQLServer,MariaDB,H2,Hive,Presto,Aurora,DM,KingbaseES | Diff raw data of records.                    |
+----------------------------+---------------------------------------------+-----------------------------------------------------------------------------------------------+----------------------------------------------+

Output Description

  • type : algorithm type
  • type_aliases: algorithm aliases
  • supported_database_types: Which databases the algorithm supports
  • description: Algorithm description

9. Perform data consistency check #

CHECK MIGRATION jobId BY TYPE (NAME='algorithmType');
NameDescription
jobIdJob id

Example

Specify the jobId to specify the check algorithm to perform data consistency verification

CHECK MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6' BY TYPE (NAME='CRC32_MATCH');

CHECK MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6' BY TYPE (NAME='DATA_MATCH', PROPERTIES('chunk-size'='1000'));

CHECK MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6' BY TYPE (NAME='SphereEx:BATCH_CRC32_MATCH');

CHECK MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6' BY TYPE (NAME='SphereEx:DATA_DIFF', PROPERTIES('diff-storage-type'='DATABASE','chunk-size'='1000','diff-storage-unit-name'='ds_2','diff-table-name'='spex_cnschk_1','incremental-idle-seconds-threshold'='30'));

10. Start The Stopped Data Consistency Check Job #

START MIGRATION CHECK jobId
NameDescription
jobIdJob id

Example

Specify the jobId to specify the check algorithm to perform data consistency verification

START MIGRATION CHECK  'j01016e501b498ed1bdb2c373a2e85e2529a6' ;
Query OK, 0 rows affected (0.09 sec)

11. Stop Data Consistency Check Job #

STOP MIGRATION CHECK jobId
NameDescription
jobIdJob id

Example

Specify the jobId to specify the check algorithm to perform data consistency verification

STOP MIGRATION CHECK  'j01016e501b498ed1bdb2c373a2e85e2529a6' ;
Query OK, 0 rows affected (0.09 sec)

12. View Progress Of Data Consistency Check #

SHOW MIGRATION CHECK STATUS jobId
NameDescription
jobIdJob id

Example

Specify the jobId to view the progress of data consistency verification:

show migration check status j0102p00009e6221cef2c4467323e205a1e4d1604b;
+-------------------+--------+---------------------+---------------------+-------------------+-------------------------+----------------+------------------+---------------+
| tables            | result | check_failed_tables | finished_percentage | remaining_seconds | check_begin_time        | check_end_time | duration_seconds | error_message |
+-------------------+--------+---------------------+---------------------+-------------------+-------------------------+----------------+------------------+---------------+
| ds_0.t_order_copy |        |                     | 0                   | 0                 | 2023-07-26 18:57:37.431 |                | 0                |               |
+-------------------+--------+---------------------+---------------------+-------------------+-------------------------+----------------+------------------+---------------+

13. Commit Job #

COMMIT MIGRATION jobId; 

Parameter Description

NameDescription
jobIdJob id

Example

Commit job specifying the jobId.

COMMIT MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6';

14. Rollback Job #

ROLLBACK MIGRATION jobId;
NameDescription
jobIdJob id

Note: This statement will clean up the target table, please operate with caution.

Example

Specify the jobId to roll back the job.

ROLLBACK MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6';

15. Register Data Migration Task Storage Unit #

REGISTER MIGRATION SOURCE STORAGE UNIT 

Parameter Description

Refer to Storage Node

Example

REGISTER MIGRATION SOURCE STORAGE UNIT ds_0 (
    URL="jdbc:mysql://127.0.0.1:3306/migration_ds_0?serverTimezone=UTC&useSSL=false",
    USER="root",
    PASSWORD="root",
    PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
);