All Products
Search
Document Center

Data Transmission Service:Data shipping

更新時間:Apr 08, 2024

Data Transmission Service (DTS) provides the data shipping feature that allows you to use the data shipping SDK to ship data from various types of data sources to DTS and then synchronize data to destination databases. This way, you can use more types of data sources.

Scenarios

You can use the data shipping feature in the following scenarios:

  • You want to synchronize data from a database that is not supported by DTS, such as a database provided by another Chinese vendor.

  • The data that you want to synchronize is the log data or data of special types.

  • The source database cannot be directly connected to DTS due to security reasons, such as the confidentiality of the database account and password.

Prerequisites

  • A destination database instance is created to receive data. Only AnalyticDB for PostgreSQL instances are supported. For more information, see Create an instance.

  • A database and a schema are created in the destination AnalyticDB for PostgreSQL instance to receive data. In this example, the dts_deliver_test schema is created. For more information, see the Import data section of the "Use SQL to import vector data" topic.

  • If you set the Access Method parameter to Express Connect, VPN Gateway, or Smart Access Gateway for the source database, you must allow DTS to access your database over a VPN gateway. For more information, see Connect a data center to DTS by using VPN Gateway.

Usage notes

  • Encoding capabilities are required if you want to use the data shipping SDK to ship data from a data source to DTS.

  • The schema name of the destination AnalyticDB for PostgreSQL instance must be the same as the database name specified in the Drop data object configuration step and the value of the dbName parameter in the data shipping SDK. Otherwise, the destination database may fail to receive data.

  • After a data shipping instance is created, you cannot change the number of shards for the instance.

  • After a data shipping instance is created, you must use the data shipping SDK to ship data at the earliest opportunity. Otherwise, incremental data cannot be collected and the instance fails.

Billing rules

For more information, see Billing overview.

Create a data shipping instance

  1. Go to the Data Synchronization Tasks page.

    1. Log on to the Data Management (DMS) console.

    2. In the top navigation bar, click DTS.

    3. In the left-side navigation pane, choose DTS (DTS) > Data Synchronization.

    Note
  2. On the right side of Data Synchronization Tasks, select the region in which the data synchronization instance resides.

    Note

    If you use the new DTS console, you must select the region in which the data synchronization instance resides in the top navigation bar.

  3. Click Create Task. In the Create Task wizard, configure the source and destination databases. The following table describes the parameters.

    Section

    Parameter

    Description

    N/A

    Task Name

    The name of the DTS task. DTS automatically generates a task name. We recommend that you specify a descriptive name that makes it easy to identify the task. You do not need to specify a unique task name.

    Source Database

    Select a DMS database instance

    Do not select an existing database instance. You must manually configure the database parameters for the data shipping task.

    Database Type

    The type of the source database. Select Data Shipping.

    Access Method

    The access method of the source database. In this example, Public IP Address is selected.

    Note

    If you select Express Connect, VPN Gateway, or Smart Access Gateway, you must also configure the VPC and vSwitch parameters for the VPN gateway that you use.

    Instance Region

    The region in which the source database resides.

    Note

    If the region in which the source database resides is not displayed in the drop-down list, select a region that is geographically closest to the source database.

    Destination Database

    Select a DMS database instance

    Select whether to use an existing instance.

    • If you select an existing instance, DTS automatically populates the parameters for the database.

    • If you do not select an existing instance, you must manually configure parameters for the database.

    Database Type

    The type of the destination database. Select AnalyticDB for PostgreSQL.

    Access Method

    The access method of the destination database. Select Alibaba Cloud Instance.

    Instance Region

    The region in which the destination AnalyticDB for PostgreSQL instance resides.

    Instance ID

    The ID of the destination AnalyticDB for PostgreSQL instance.

    Database Name

    The name of the database that is used to receive data in the destination AnalyticDB for PostgreSQL instance.

    Database Account

    The database account of the destination AnalyticDB for PostgreSQL instance. The account must have the read and write permissions on the destination database. For more information about how to create a database account, see Create a database account.

    Database Password

    The password of the database account.

  4. In the lower part of the page, click Test Connectivity and Proceed.

    If the source or destination database is an Alibaba Cloud database instance, such as an ApsaraDB RDS for MySQL or ApsaraDB for MongoDB instance, DTS automatically adds the CIDR blocks of DTS servers to the whitelist of the instance. If the source or destination database is a self-managed database hosted on an Elastic Compute Service (ECS) instance, DTS automatically adds the CIDR blocks of DTS servers to the security group rules of the ECS instance, and you must make sure that the ECS instance can access the database. If the database is deployed on multiple ECS instances, you must manually add the CIDR blocks of DTS servers to the security group rules of each ECS instance. If the source or destination database is a self-managed database that is deployed in a data center or provided by a third-party cloud service provider, you must manually add the CIDR blocks of DTS servers to the whitelist of the database to allow DTS to access the database. For more information, see Add the CIDR blocks of DTS servers.

    Warning

    If the CIDR blocks of DTS servers are automatically or manually added to the whitelist of the database or instance, or to the ECS security group rules, security risks may arise. Therefore, before you use DTS to synchronize data, you must understand and acknowledge the potential risks and take preventive measures, including but not limited to the following measures: enhancing the security of your username and password, limiting the ports that are exposed, authenticating API calls, regularly checking the whitelist or ECS security group rules and forbidding unauthorized CIDR blocks, or connecting the database to DTS by using Express Connect, VPN Gateway, or Smart Access Gateway.

  5. Configure the objects to be shipped and advanced settings.

    Parameter

    Description

    Processing Mode of Conflicting Tables

    • Precheck and Report Errors: checks whether the destination database contains tables that have the same names as tables in the source database. If the source and destination databases do not contain tables that have identical table names, the precheck is passed. Otherwise, an error is returned during the precheck and the data synchronization task cannot be started.

      Note

      If the source and destination databases contain identical table names and the tables in the destination database cannot be deleted or renamed, you can use the object name mapping feature to rename the tables that are synchronized to the destination database. For more information, see Map object names.

    • Ignore Errors and Proceed: skips the precheck for identical table names in the source and destination databases.

      Warning

      If you select Ignore Errors and Proceed, data inconsistency may occur and your business may be exposed to the following potential risks:

      • If the source and destination databases have the same schema and a data record in the destination database has the same primary key value or unique key value as a data record in the source database:

        • During full data synchronization, DTS does not synchronize the data record to the destination database. The existing data record in the destination database is retained.

        • During incremental data synchronization, DTS synchronizes the data record to the destination database. The existing data record in the destination database is overwritten.

      • If the source and destination databases have different schemas, data may fail to be initialized. In this case, only some columns are synchronized, or the data synchronization task fails. Proceed with caution.

    Capitalization of Object Names in Destination Instance

    The capitalization of database names, table names, and column names in the destination instance. By default, DTS default policy is selected. You can select other options to ensure that the capitalization of object names is consistent with that in the source or destination database. For more information, see Specify the capitalization of object names in the destination instance.

    Drop data object configuration

    1. Click Add Library. In the New Database dialog box, enter the name of the source database.

      Important
      • The name of the source database must be the same as the schema name of the destination AnalyticDB for PostgreSQL instance. In this example, dts_deliver_test is entered.

      • If a database is displayed in the list and you want to add a new one, click Add to the right of the existing database.

    2. Click OK.

    3. Click the image.png icon to the left of the database that you added to view the database list.

    4. Click Add Table to the right of Table. In the Add Table dialog box, enter the table name.

      Important

      The table name of the source database must be consistent with the tableName parameter specified in the data shipping SDK. In this example, tab1, tab2, and tab3 are entered. For more information, see the parameters described in the Use the SDK to ship data to DTS section of this topic.

    5. Click OK.

    6. Optional. Configure the mappings between table names and column names.

      1. Click Edit to the right of the table that you created.

      2. Configure the table name mappings.

        Modify the Table Name parameter.

      3. Configure the column name mappings.

        Clear Synchronize All Tables, and then modify the Column Name and Map column name parameters.

        Important
        • The Column Name and Map column name parameters must be used together with the data shipping SDK. The value of the Column Name parameter is the name in the createField method of the FakeSource.java file. The value of the Map column name parameter is the name of the column in the destination AnalyticDB for PostgreSQL instance.

        • Click the image.png button to add more columns.

      4. After the configuration is complete, click OK.

        Note

        You can repeat the preceding steps to add, edit, or delete databases or tables based on your business requirements.

  6. Click Next: Advanced Settings to configure advanced settings. The following table describes the parameters.

    Parameter

    Description

    Select the dedicated cluster used to schedule the task

    By default, DTS schedules the task to a shared cluster. You do not need to configure this parameter. You can also purchase a dedicated cluster of the specified specifications to run DTS tasks. For more information, see What is a DTS dedicated cluster?

    Set Alerts

    Specifies whether to configure alerting for the data synchronization task. If the task fails or the synchronization latency exceeds the specified threshold, alert contacts will receive notifications. Valid values:

    • No: does not configure alerting.

    • Yes: configures alerting. In this case, you must also configure the alert threshold and alert contacts. For more information, see Configure monitoring and alerting.

    Retry Time for Failed Connections

    The retry time range for failed connections. If the source or destination database fails to be connected after the data synchronization task is started, DTS immediately retries a connection within the time range. Valid values: 10 to 1440. Unit: minutes. Default value: 720. We recommend that you set this parameter to a value greater than 30. If DTS reconnects to the source and destination databases within the specified time range, DTS resumes the data synchronization task. Otherwise, the data synchronization task fails.

    Note
    • If you specify different retry time ranges for multiple data synchronization tasks that have the same source or destination database, the shortest retry time range takes precedence.

    • When DTS retries a connection, you are charged for the DTS instance. We recommend that you specify the retry time range based on your business requirements. You can also release the DTS instance at your earliest opportunity after the source and destination instances are released.

    The wait time before a retry when other issues occur in the source and destination databases.

    The retry time range for other issues. For example, if the DDL or DML operations fail to be performed after the data synchronization task is started, DTS immediately retries the operations within the time range. Valid values: 1 to 1440. Unit: minutes. Default value: 10. We recommend that you set this parameter to a value greater than 10. If the failed operations are successfully performed within the specified time range, DTS resumes the data synchronization task. Otherwise, the data synchronization task fails.

    Important

    The value of the The wait time before a retry when other issues occur in the source and destination databases. parameter must be smaller than the value of the Retry Time for Failed Connections parameter.

    Enable Throttling for Incremental Data Synchronization

    Specifies whether to enable throttling for incremental data synchronization. You can enable throttling for incremental data synchronization based on your business requirements. To configure throttling, you must configure the RPS of Incremental Data Migration and BPS of Incremental Data Migration parameters. This reduces the load on the destination database server.

    Environment Tag

    The environment tag that is used to identify the DTS instance. You can select an environment tag based on your business requirements.

    Configure ETL

    Specifies whether to enable the extract, transform, and load (ETL) feature. For more information, see What is ETL? Valid values:

  7. Save the task settings and run a precheck.

    • To view the parameters to be specified when you call the relevant API operation to configure the DTS task, move the pointer over Next: Save Task Settings and Precheck and click Preview OpenAPI parameters.

    • If you do not need to view or have viewed the parameters, click Next: Save Task Settings and Precheck in the lower part of the page.

    Note
    • Before you can start the data synchronization task, DTS performs a precheck. You can start the data synchronization task only after the task passes the precheck.

    • If the task fails to pass the precheck, click View Details next to each failed item. After you analyze the causes based on the check results, troubleshoot the issues. Then, run a precheck again.

    • If an alert is triggered for an item during the precheck:

      • If an alert item cannot be ignored, click View Details next to the failed item and troubleshoot the issue. Then, run a precheck again.

      • If an alert item can be ignored, click Confirm Alert Details. In the View Details dialog box, click Ignore. In the message that appears, click OK. Then, click Precheck Again to run a precheck again. If you ignore the alert item, data inconsistency may occur and your business may be exposed to potential risks.

  8. Wait until the success rate becomes 100%. Then, click Next: Purchase Instance.

  9. On the Purchase Instance page, configure the Billing Method and Instance Class parameters for the data synchronization instance. The following table describes the parameters.

    Category

    Parameter

    Description

    New Instance Class

    Billing Method

    • Subscription: You pay for your subscription when you create an instance. The subscription billing method is more cost-effective than the pay-as-you-go billing method for long-term use.

    • Pay-as-you-go: A pay-as-you-go instance is billed on an hourly basis. We recommend that you select the pay-as-you-go billing method for short-term use. If you no longer require a pay-as-you-go instance, you can release the instance to reduce costs.

    Number of Shards

    The number of partitions in the destination topic.

    Important

    After an instance is created, you cannot change the number of shards for the instance. Proceed with caution.

    Resource Group Settings

    The resource group to which the instance belongs. Default value: default resource group. For more information, see What is Resource Management?

    Instance Class

    DTS provides various synchronization specifications that provide different performance. The synchronization speed varies based on the synchronization specifications that you select. You can select a synchronization specification based on your business requirements. For more information, see Specifications of data synchronization instances.

    Subscription Duration

    If you select the subscription billing method, set the subscription duration and the number of instances that you want to create. The subscription duration can be one to nine months, one year, two years, three years, or five years.

    Note

    This parameter is available only if you select the Subscription billing method.

  10. Read and select the Data Transmission Service (Pay-as-you-go) Service Terms.

  11. Click Buy and Start to start the data synchronization task. You can view the progress of the task in the task list.

Use the SDK to ship data to DTS

  1. Configure the data shipping SDK.

    1. Open an SDK development tool, such as IntelliJ IDEA, and create a business project.

    2. In the project that you created, find the pom.xml file.

    3. Add the following dependency to the pom.xml file:

      <dependency>
        <groupId>com.aliyun.dts.deliver</groupId>
        <artifactId>dts-deliver-client</artifactId>
        <version>1.0.0</version>
      </dependency>
      Note

      You can view the latest version of the data shipping SDK on the dts-deliver-client page.

    4. Download the sample code and then modify the sample code based on the DtsDeliverTest.java file in the dts-deliver-test folder. For more information, see dts-deliver-test.

      Note

      In the FakeSource.java file, the read method provides an example of the data source and the name in the createField method is the column name of the source table. Perform encoding based on the actual situation.

      On the Data Synchronization Tasks page, click the ID of the data shipping instance that you created. On the instance details page, click Basic Information in the left-side pane to obtain the values of parameters for the data shipping SDK. The following table describes the parameters.

      Parameter

      Description

      Method to obtain the parameter value

      ip:port

      The endpoint of the data shipping instance.

      In the Shipping Channel Information section, click Copy to the right of the Public Endpoint or VPC Endpoint parameter.

      Important

      You can use the VPC Endpoint only if the source database resides in the VPC of the data shipping instance.

      ak

      The AccessKey ID and AccessKey secret of the account to which the data shipping instance belongs.

      For more information, see Create an AccessKey pair and View the information about AccessKey pairs of a RAM user.

      secret

      dts_job_id

      Note

      The information to be entered in DTS_JOB_ID.getKey().

      The task ID of the data shipping instance.

      Important

      Do not enter the ID of the data shipping instance.

      You can call the DescribeDtsJobs operation to query the task ID.

      Note

      Obtain the value of the Shipped Topic parameter and set the dts_job_id parameter to the field between _vpc_ and _data_delivery_ of the value. For example, if the value of the Shipped Topic parameter is cn_hangzhou_vpc_cxti86dc11z***_data_delivery_version2, set the dts_job_id parameter to cxti86dc11z***.

      topic

      The destination topic of the data shipping instance.

      In the Shipping Channel Information section, click Copy to the right of the Shipped Topic parameter.

      partition

      The number of shards in the destination topic.

      In the Shipping Channel Information section, view the number of shards in the destination topic.

      region

      The region in which the data shipping instance resides.

      In the Shipping Channel Information section, view the value of the Instance Region parameter.

      dbName

      The name of the source database. The name of the source database must be the same as the schema name of the destination AnalyticDB for PostgreSQL instance.

      In this example, dts_deliver_test is entered.

      tableName

      The name of the source table. The name of the source table must be the same as the table name that you specified in the Drop data object configuration step.

      In this example, tab1, tab2, and tab3 are entered.

  2. After the parameters are configured, record the current time and start the data shipping SDK.

  3. Modify the current offset of the data shipping instance. For more information, see Change the current offset of a data synchronization or migration instance.

    Note

    By default, the Current Offset of the data shipping instance is the point in time at which the Incremental Write module starts to run. You need to change the current offset to the point in time at which the data shipping SDK starts to run.

  4. View the data synchronized to the destination database.