Using a generic MySQL data source to synchronize data from PolarDB-X 2.0 in DataWorks can lead to inefficient parallel reads, excessive database resource consumption, or task failures. To ensure efficient and stable data synchronization, use the dedicated data source type optimized for PolarDB-X 2.0. This topic explains how to configure and use the PolarDB-X 2.0 data source and introduces its unique optimization parameters.
Overview
The PolarDB-X 2.0 data source in DataWorks is designed for the distributed architecture of PolarDB-X. Unlike a generic MySQL data source, it can identify the topology of PolarDB-X partitioned tables, enabling parallel data reads by partition. This optimized read pattern maximizes the use of database resources, significantly improves data synchronization performance, and prevents inefficient scan methods from impacting production workloads.
Scope
This feature applies only to PolarDB-X 2.0 instances.
If you are using a PolarDB-X 1.0 instance, select the DRDS (PolarDB-X 1.0) data source.
Procedure
Step 1: Configure account permissions
To run a data synchronization task, the database account must have the following permissions.
-
Offline synchronization:
-
Offline read (Reader): The account must have
SELECTpermission on the destination database.NoteBefore execution, the Reader retrieves table topology information by running the
SHOW TOPOLOGY FROM <table_name>command. Therefore, ensure the account has read permission on the destination database. -
Offline write (Writer): The account must have
INSERT,DELETE, andUPDATEpermissions on the destination table.
-
-
Real-time synchronization (entire database):
-
A privileged account can read the binary log by default for real-time synchronization.
-
A standard account must be granted
SELECT,REPLICATION SLAVE, andREPLICATION CLIENTpermissions by a privileged account.
-
Step 2: Create a data source
When you add a data source in the DataWorks console, you must select PolarDB-X 2.0. For information about other parameters and configurations, see Create a data source.
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Management Center.
In the navigation pane on the left, click Data Source to go to the Data Source List page.
In the upper-left corner of the page, click Add Data Source.
In the Add Data Source dialog box, click the Relational Databases category, and then select PolarDB-X 2.0.
Step 3: (Optional) Use custom endpoints for workload isolation
If many DataWorks tasks create high load on specific compute nodes, you can achieve workload isolation by routing DataWorks traffic to dedicated compute nodes using a custom endpoint.
-
-
Go to the PolarDB-X console and navigate to the target instance.
-
In the left-side navigation pane, click .
-
Go to the Custom Endpoint tab and click Create Custom Connection to configure the parameters.
Note-
If your instance is a three-zone instance, it includes standby compute nodes. These standby compute nodes do not handle business traffic and are ideal for DataWorks. In the Compute node list on the instance details page, you can find inactive nodes, which are the standby nodes. On the Topology Information page, in the Compute Node List, nodes with the master role have an Activated status and nodes with the standby role have a Not Activated status. These roles are typically located in different zones.
-
If your instance is not a three-zone instance, you can do one of the following:
-
Change the deployment from a single zone to three zones. A three-zone instance costs the same as a single-zone instance.
-
Create multiple custom endpoints for your business services and DataWorks.
-
-
-
Use the custom endpoint in DataWorks: When you create or modify a DataWorks data source, select Connection String Mode for Configuration Method and enter the previously created custom endpoint in the Host Address/IP field.
Step 4: Configure a data synchronization task
We recommend using the code editor to configure the data synchronization task, as some advanced parameters can only be set there. For detailed steps and instructions, see Configure an offline synchronization task by using the code editor.
Reader
The following table describes the core parameters for the Reader. Some advanced parameters are available only in the code editor.
|
Parameter |
Description |
Required |
Default |
|
|
The name of the source table to synchronize. Only a single table can be specified. |
Yes |
None |
|
|
The columns to read, defined as a JSON array.
The following code shows a complex example:
|
Yes |
None |
|
|
The data filtering condition is directly appended to the Note
The filter condition is not applied at the DataWorks layer but is appended directly to the SQL query. For example, the preceding example is equivalent to running the
We do not recommend that you use this parameter to specify filter conditions on a production database. If you must use this parameter, carefully evaluate the performance of the SQL query. |
No |
None |
|
|
This is a core optimization parameter. For partitioned tables, we recommend setting this parameter to Note
When you use the |
No |
|
|
|
This parameter is deprecated. |
No |
None |
Sample script
{
"stepType": "polardbx20",
"parameter": {
"checkSlave": "false",
"slaveDelayLimit": "300",
"datasource": "ms_polardbx",
"envType": 1,
"column": ["c1+c2",
"FROM_UNIXTIME(c3)",
"CAST(c4 AS SIGNED)",
"c5",
"c5",
"c5",
"IFNULL(c6,0)",
"IF(c7>10,c7,c8)",
],
"tableComment": "",
"onePartitionOneTask":true // Recommended when reading data from a partitioned table.
},
"name": "Reader",
"category": "reader"
}
Writer
The following table describes the core parameters for the Writer.
|
Parameter |
Description |
Required |
Default |
|
|
The name of the destination table. |
Yes |
None |
|
|
The import mode. The following modes are supported:
|
No |
|
|
|
Used with the |
No |
None |
|
|
The names of the destination table columns, separated by commas (,). Example: |
Yes |
None |
|
|
An SQL statement to execute before the data synchronization task starts. The codeless UI allows only a single SQL statement, while the code editor supports multiple SQL statements. |
No |
None |
|
|
An SQL statement to execute after the data synchronization task is complete. The codeless UI allows only a single SQL statement, while the code editor supports multiple SQL statements. |
No |
None |
|
|
The number of records to write per batch. Increasing this value can reduce the number of network interactions between the data synchronization system and PolarDB-X 2.0, which improves overall throughput. However, a value that is too high increases memory consumption and may cause out-of-memory errors. |
No |
256 |
|
|
Specifies whether to enable automatic retries for issues such as deadlocks or lock wait timeouts. If the table has a primary key or unique key, we recommend that you set this parameter to Note
If the table does not have a primary key or unique key, retrying may cause data duplication. |
No |
|
|
|
Used with |
No |
["Lock wait timeout exceeded", "Deadlock found when trying to get lock", "Query execution was interrupted"] |
|
|
Used with |
No |
100 |
|
|
Specifies whether to automatically reconnect and retry a task after a connection is interrupted, for example, due to a transient network issue or a primary/standby failover. If the table has a primary key or unique key, we recommend that you set this parameter to Note
If the table does not have a primary key or unique key, retrying may cause data duplication. |
No |
|
Sample script
{
"stepType": "polardbx20",
"parameter": {
"postSql": [],
"datasource": "ms_polardbx",
"envType": 1,
"column": [
"id",
"c1",
"c2",
"c3",
"c4"
],
"tableComment": "",
"writeMode": "insert ignore",
"batchSize": 256,
"table": "tbl",
"preSql": [],
"enableRetry": true, // Recommended if the table has a primary or unique key.
"enableReConnect": true // Recommended if the table has a primary or unique key.
},
"name": "Writer",
"category": "writer"
}