You can call the API operations of Data Transmission Service (DTS) to configure or query the objects of a data migration, data synchronization, or change tracking task. This topic describes the related API operations and provides object definitions and configuration examples.
Related API operations and parameters
API | Description |
You can use the request parameter | |
You can use the response parameter |
Object definitions
The value of an object-related parameter is a JSON string. This section describes object-related parameters.
If the objects include multiple databases, refer to the following parameter description to define the objects:
{ "The name of source database 1": { "name": "The database name that you want to use for source database 1 in the destination instance", "all": true (indicates that the entire database is used as the source object) }, "The name of source database 2": { "name": "The database name that you want to use for source database 2 in the destination instance", "all": false (indicates that the source object is not the entire database), "Table": { "The name of source table A": { "name": "The table name that you want to use for source table A in the destination instance", "all": true (indicates that the entire table is used as the source object), "dml_op": "The DML operations that you want to migrate or synchronize during incremental data migration or synchronization", "ddl_op": "The DDL operations that you want to migrate or synchronize during incremental data migration or synchronization" } } }, "The name of source database 3": { "name": "The database name that you want to use for source database 3 in the destination instance", "all": true (indicates that the entire database is used as the source object), "dml_op": "The DML operations that you want to migrate or synchronize during incremental data migration or synchronization", "ddl_op": "The DDL operations that you want to migrate or synchronize during incremental data migration or synchronization" } }
If the objects are specific columns or include filter conditions, refer to the following parameter description to define the objects:
{ "The name of the source database": { "name": "The database name that you want to use for the source database in the destination instance", "all": false (indicates that the source object is not the entire database), "Table": { "The name of source table A": { "name": "The table name that you want to use for source table A in the destination instance", "all": false (indicates that the source object is not the entire table), "filter": "id>10" "column": { "id": { "key": "PRI", "name": "id", "type": "int(11)", "sharedKey": false, "state": "checked" } }, "shard": 12 } } } }
If you migrate or synchronize objects to an AnalyticDB for MySQL cluster or an AnalyticDB for PostgreSQL instance, refer to the following parameter description to define the objects:
{ "The name of the source database": { "name": "The database name that you want to use for the source database in the destination instance", "all": false (fixed value) You must set the value to false if you migrate objects to an AnalyticDB for MySQL cluster or an AnalyticDB for PostgreSQL instance, regardless of whether the objects are specific tables or an entire database. In this case, you must also specify the partition key that corresponds to each table. "Table": { "The name of source table A": { "all": true (indicates that the entire table is used as the source object), "name": "The table name that you want to use for source table A in the destination instance", "primary_key": "The primary key. Example: id", "type": "The table type. Example: dimension", } "The name of source table B": { "all": true (indicates that the entire table is used as the source object), "name": "The table name that you want to use for source table B in the destination instance", "part_key": "The partition key. Example: id", "primary_key": "The primary key. Example: id", "type": "The table type. Example: partition", "tagColumnValue": "The tag column value" } } } }
If an independent conflict resolution policy is specified for the objects to be synchronized, refer to the following parameter description to define the objects:
NoteThe independent conflict resolution policy is supported only for two-way data synchronization between MySQL databases or between PolarDB for MySQL clusters.
You can configure independent conflict resolution policies at the database level or table level.
The global conflict resolution policy does not apply to the columns for which an independent conflict resolution policy is specified.
Table-level policy
{ "The name of source database 1": { "name": "The database name that you want to use for source database 1 in the destination instance", "all": true (indicates that the entire database is used as the source object), "conflict": "Task-level conflict resolution policy" }, "Name of source database 2": { "name": "The database name that you want to use for source database 2 in the destination instance", "all": false (indicates that the source object is not the entire database), "conflict": "overwrite", "Table": { "The name of source table A": { "name": "The table name that you want to use for source table A in the destination instance", "all": true (indicates that the entire table is used as the source object), "cdr_cmp_col": "Columns for conflict detection", "cdr_rslv_col": "Columns for conflict detection", "resolve_method": "Table-level conflict resolution policy" } } } }
Database-level policy
If the object to be synchronized is the entire database, use the following code to define independent conflict resolution policies:
"Name of source database 1": { "name": "The database name that you want to use for source database 1 in the destination instance", "all": true (indicates that the entire database is used as the source object), "conflict": "Task-level conflict resolution policy", "cdr_cmp_col": "Columns for conflict detection", "cdr_rslv_col": "Columns for conflict detection", "resolve_method": "Database-level conflict resolution policy" } }
If the object to be synchronized is not the entire database, use the following code to define independent conflict resolution policies:
"Name of source database 2": { "name": "The database name that you want to use for source database 2 in the destination instance", "all": false (indicates that the source object is not the entire database), "conflict": "Task-level conflict resolution policy", "cdr_cmp_col": "Columns for conflict detection", "cdr_rslv_col": "Columns for conflict detection", "resolve_method": "Database-level conflict resolution policy", "Table": { "The name of source table A": { "name": "The table name that you want to use for source table A in the destination instance", "all": true (indicates that the entire table is used as the source object) } } }
Parameter | Description |
| The database name, table name, or column name that you want to use in the destination instance. For example, if you want to migrate data from a database named dtssource to a database named dtstarget, you must set the name parameter to dtstarget. |
| Specifies whether to select all tables or columns. Valid values:
|
| The information about the source table. |
| The condition used to filter the source data. The filter condition takes effect only at the table level. For example, you can enter Note You cannot specify filter conditions for change tracking tasks. |
| The information about the source column. |
| Specifies whether to use the column as the primary key. Valid values:
|
| Specifies whether to use the column as the shard key. Valid values:
Note This parameter is required only if the source database is a Kafka instance. |
| The data type of the column. |
| The state of the column. If this parameter is set to |
| The number of shards in the source table. Note This parameter is required only if the source database is a Kafka instance. |
| The DML operations that you want to migrate or synchronize during incremental data migration or synchronization. Valid values:
Note For more information about the DML operations supported by different data migration or synchronization tasks, see the topics listed in Overview of data migration scenarios or Overview of data synchronization scenarios. |
| The DDL operations that you want to migrate or synchronize during incremental data migration or synchronization. Valid values:
Note For more information about the DDL operations supported by different data migration or synchronization tasks, see the topics listed in Overview of data migration scenarios or Overview of data synchronization scenarios. |
| The primary key. This parameter is valid and required only if the destination instance is an AnalyticDB for MySQL cluster or an AnalyticDB for PostgreSQL instance. |
| The partition key. This parameter is valid and required only if the destination instance is an AnalyticDB for MySQL cluster or an AnalyticDB for PostgreSQL instance. |
Important The | The type of the source table. This parameter is required if the destination instance is an AnalyticDB for MySQL cluster or an AnalyticDB for PostgreSQL instance. Valid values:
|
| The custom value of the __dts_data_source tag column. This parameter is valid and required only if the destination instance is an AnalyticDB for MySQL cluster. |
| The global conflict resolution policy at the task level. You must specify a value for this parameter for each source database and the values that you specify must be the same. Valid values:
|
| The independent conflict resolution policy at the table level. The independent conflict resolution policy is supported only for incremental data synchronization. Valid values:
|
|
|
|
Configuration examples
Example 1: Replicate data from all tables in the dtstestdata database.
{"dtstestdata": { "name": "dtstestdata", "all": true }}
Example 2: Replicate data from all tables in the dtstestdata database and change the database name to dtstestdata_new.
{"dtstestdata": { "name": "dtstestdata_new", "all": true }}
Example 3: Replicate data from a table named customer in the dtstestdata database.
{"dtstestdata": { "name": "dtstestdata", "all": false, "Table": { "customer": { "name": "customer", "all": true, "column": { "id": { "key": "PRI", "name": "id", "type": "int(11)", "sharedKey": false, "state": "checked" }, "gmt_create": { "key": "", "name": "gmt_create", "type": "datetime", "sharedKey": false, "state": "checked" }, "gmt_modify": { "key": "", "name": "gmt_modify", "type": "datetime", "sharedKey": false, "state": "checked" }, "valid_time": { "key": "", "name": "valid_time", "type": "datetime", "sharedKey": false, "state": "checked" }, "creator": { "key": "", "name": "creator", "type": "varchar(200)", "sharedKey": false, "state": "checked" } }, "shard": 12 } } } }
Example 4: Replicate data from specific columns of the customer and order tables in the dtstestdata database.
{"dtstestdata": { "name": "dtstestdata", "all": false, "Table": { "customer": { "name": "customer", "all": false, "column": { "id": { "key": "PRI", "name": "id", "type": "int(11)", "sharedKey": false, "state": "checked" }, "level": { "key": "", "name": "level", "type": "varchar(5000)", "sharedKey": false, "state": "checked" }, "name": { "key": "", "name": "name", "type": "varchar(500)", "sharedKey": false, "state": "checked" }, }, "shard": 12 }, "order": { "name": "order", "all": false, "column": { "id": { "key": "PRI", "name": "id", "type": "int(11)", "sharedKey": false, "state": "checked" } }, "shard": 12 } } } }
Example 5: Replicate data from the customer, order, and commodity tables in the dtstestdata database to the destination AnalyticDB for MySQL cluster or AnalyticDB for PostgreSQL instance.
{ "dtstestdata": { "name": "dtstestdatanew", "all": false, "Table": { "order": { "name": "ordernew", "all": true, "part_key": "id", "primary_key": "id", "type": "partition" }, "customer": { "name": "customernew", "all": true, "primary_key": "id", "type": "dimension" }, "commodity": { "name": "commoditynew", "all": false, "filter": "id>10", "column": { "id": { "key": "PRI", "name": "id", "type": "int(11)" } }, "part_key": "id", "primary_key": "id", "type": "partition" } } } }
Example 6:
Table-level policy
The following sample code provides an example on how to configure a global conflict resolution policy named
interrupt
for the objects to be synchronized and configure an independent conflict resolution policy namedoverwrite
for the primary key column, unique key column, andname
column of the customer table in the dtstestdata2 database to be synchronized.{ "dtstestdata1": { "name": "dtstestdata1", "all": true, "conflict": "interrupt" }, "dtstestdata2": { "name": "dtstestdata2", "all": false, "conflict": "interrupt", "Table": { "customer": { "name": "customer", "all": true, "cdr_cmp_col": "name", "cdr_rslv_col": "name", "resolve_method": "overwrite" } } } }
Database-level policy
Synchronize an entire database named dtstestdata1: The following sample code provides an example on how to configure an independent conflict resolution policy named
use_max
for thename
andaddr
columns of all tables in the dtstestdata1 database."dtstestdata1": { "name": "dtstestdata1", "all": true, "conflict": "overwrite", "cdr_cmp_col": "name,addr", "cdr_rslv_col": "name,addr", "resolve_method": "use_max" } }
Synchronize a part of a database named dtstestdata2: The following sample code provides an example on how to configure an independent conflict resolution policy named
use_max
for thename
andaddr
columns of all tables to be synchronized in the dtstestdata2 database."dtstestdata2": { "name": "dtstestdata2", "all": false, "conflict": "overwrite", "cdr_cmp_col": "name,addr", "cdr_rslv_col": "name,addr", "resolve_method": "use_max", "Table": { "person": { "name": "person", "all": true }, "class": { "name": "class", "all": true } } }
Example 7: Assume that Source Database Type is set to Tair/Redis for a data synchronization instance. The following code indicates that a data record in the database named 0 or 1 is synchronized only if the key prefix is
HProp
(HProp
as Prefixes of Keys to Be Synchronized). In the database named 2, a data record is synchronized only if the key prefix isdts
and does not containdtstest
(dts
as Prefixes of Keys to Be Synchronized anddtstest
as Prefixes of Keys to Be Filtered Out).{ "0": { "name": "0", "all": true, "filter": "[{"condition":"HProp","filterType":"white","filterPattern":"prefix"}]" }, "1": { "name": "1", "all": true, "filter": "[{"condition":"HProp","filterType":"white","filterPattern":"prefix"}]" }, "2": { "name": "2", "all": true, "filter": "[{"condition":"dts","filterType":"white","filterPattern":"prefix"},{"condition":"dtstest","filterType":"black","filterPattern":"prefix"}]" } }