Migrate data from PolarDB for MySQL to ApsaraMQ for RocketMQ

Updated at:

Use Data Transmission Service (DTS) to migrate data from a PolarDB for MySQL cluster to an ApsaraMQ for RocketMQ instance. DTS supports full data migration and incremental data migration, so you can cut over with minimal downtime.

Note

This feature is in beta testing and is available only to select users.

Prerequisites

Before you begin, make sure you have:

For supported source and destination database versions, see Overview of migration solutions.

Limitations

Source database

  • The server hosting the source database must have enough outbound bandwidth. Low bandwidth reduces migration speed.

  • Tables to be migrated must have PRIMARY KEY or UNIQUE constraints, with all fields unique. Without these constraints, the destination may contain duplicate records.

  • DTS does not migrate read-only nodes or Object Storage Service (OSS) external tables from the source PolarDB for MySQL cluster.

  • When migrating tables and renaming them (or their columns) in the destination, a single migration task supports up to 1,000 tables. To migrate more, split the work across multiple tasks, or migrate the entire database instead of individual tables.

  • Do not perform DDL operations that change the schema during full data migration. DTS queries the source database during full migration, creating metadata locks that block DDL operations.

  • If you run only full data migration, do not write new data to the source database during migration. Otherwise the source and destination databases become inconsistent.

  • Data changes generated by binary log operations — such as data restored from a physical backup or cascade operations — are not captured and migrated while the migration task is running.

Incremental migration requirements

To enable incremental data migration, configure the following binary logging settings on the source PolarDB for MySQL cluster:

Parameter

Required value

Notes

Binary logging feature

Enabled

See Enable binary logging. Enabling binary logging incurs storage charges for log files.

loose_polar_log_bin

on

See Modify parameters.

Binary log retention period

At least 3 days (7 days recommended)

If logs are purged before DTS reads them, the task fails and data loss may occur. See Modify the retention period.

Important

If the retention period is too short and DTS cannot read the required binary logs, the service reliability and performance stated in the DTS SLA may not be guaranteed.

Destination instance

  • The destination ApsaraMQ for RocketMQ instance must be non-serverless.

  • You can only migrate data to some topics of a destination ApsaraMQ for RocketMQ instance. The destination topic must use the correct message type: Partitionally Ordered Message for RocketMQ V4.x, or Ordered Message for RocketMQ V5.x.

  • Message bodies larger than 4 MB are not supported. Set Whether to filter large size of records to Yes to skip oversized messages — if left unfiltered, a message body exceeding 4 MB causes the migration task to fail.

  • For RocketMQ V4.x: if the destination instance is in a different region from the source, DTS accesses it over the Internet. Enable Internet access on the destination instance; Internet traffic fees apply. Check Internet access status on the Basic Information tab of the Instance Details page in the ApsaraMQ for RocketMQ console. For fee details, see Billing of Internet traffic.

  • Upgrading or downgrading the instance class of the destination ApsaraMQ for RocketMQ instance changes the message delivery rule configuration.

Operational constraints

  • Do not use tools such as pt-online-schema-change for online DDL operations on the objects being migrated. This causes the migration task to fail.

  • Do not write data from other sources to the destination database during migration. This causes data inconsistency.

  • DTS does not support primary/secondary switchover during full migration. If a switchover occurs, reconfigure the migration task immediately.

  • During full data migration, DTS consumes read and write resources on both the source and destination. Run full migration during off-peak hours, when CPU usage on both databases is below 30%.

  • After full data migration, the destination tablespace is larger than the source due to fragmentation from concurrent INSERT operations.

  • DTS periodically executes CREATE DATABASE IF NOT EXISTS `test` on the source database to advance the binary log file position.

  • If a DTS instance fails, the DTS helpdesk attempts to restore it within 8 hours. Recovery may involve restarting the instance or adjusting DTS parameters (not database parameters). For parameters that may be modified, see Modify instance parameters.

Billing

Migration type

Fee

Full data migration

Free

Incremental data migration

Charged. See Billing overview.

SQL operations supported for incremental migration

Operation type

SQL statements

DML

INSERT, UPDATE, DELETE

DDL

CREATE TABLE, ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE

Create a migration task

Step 1: Open the Data Migration page

Use one of the following consoles:

DTS console

  1. Log on to the DTS console.

  2. In the left-side navigation pane, click Data Migration.

  3. In the upper-left corner of the page, select the region where the migration instance resides.

DMS console

Note

The actual steps may vary based on the DMS console mode and layout. See Simple mode and Customize the layout and style of the DMS console.

  1. Log on to the DMS console.

  2. In the top navigation bar, move the pointer over Data + AI > DTS (DTS) > Data Migration.

  3. From the drop-down list to the right of Data Migration Tasks, select the region where the migration instance resides.

Step 2: Configure source and destination databases

  1. Click Create Task.

  2. Configure the source database:

    Parameter

    Value

    Task Name

    Enter a descriptive name to identify the task. The name does not need to be unique.

    Select Existing Connection

    Select a registered database instance, or configure the connection manually.

    Database Type

    Select PolarDB for MySQL.

    Access Method

    Select Alibaba Cloud Instance.

    Instance Region

    Select the region where the source PolarDB for MySQL cluster resides.

    Replicate Data Across Alibaba Cloud Accounts

    Select No if using a database instance from the current Alibaba Cloud account.

    PolarDB Cluster ID

    Select the ID of the source PolarDB for MySQL cluster.

    Database Account

    Enter the database account with the required permissions.

    Database Password

    Enter the password for the database account.

    Encryption

    Select SSL-encrypted if SSL encryption is enabled on the source cluster. See Configure SSL encryption.

  3. Configure the destination database:

    Parameter

    Value

    Select Existing Connection

    Select a registered database instance, or configure the connection manually.

    Database Type

    Select RocketMQ.

    Access Method

    Select Alibaba Cloud Instance.

    Instance Region

    Select the region where the destination ApsaraMQ for RocketMQ instance resides.

    RocketMQ version

    Select the version of the destination instance (4.x or 5.x).

    Instance ID

    Select the ID of the destination ApsaraMQ for RocketMQ instance.

    Database Account

    Required for RocketMQ V5.x only. Get the account on the Intelligent Authentication tab of the Access Control page in the ApsaraMQ for RocketMQ console.

    Database Password

    Required for RocketMQ V5.x only.

    Topic

    Select the topic to receive the migrated data.

    Topic That Stores DDL Information

    Select a topic to store DDL change records. If left blank, DDL information is stored in the topic selected for Topic.

  4. Click Test Connectivity and Proceed.

    Note

    Make sure the CIDR blocks of DTS servers are added to the security settings of the source and destination databases. See Add DTS server IP addresses to a whitelist.

Step 3: Configure objects to migrate

  1. On the Configure Objects page, set the following options:

    Parameter

    Description

    Migration Types

    Select Full Data Migration only for a one-time migration. Select both Full Data Migration and Incremental Data Migration to keep source and destination in sync during migration.

    Processing Mode of Conflicting Tables

    Precheck and Report Errors: fails the precheck if the destination contains tables with the same names as the source. Ignore Errors and Proceed: skips this check, which may cause data inconsistency.

    Format of the data delivered to RocketMQ.

    The format in which migrated data is written to the topic. See Data formats in a message queue.

    Synchronize all fields

    Applies only when the format is Canal JSON. Controls whether UPDATE operations include the pre-image of the modified fields in the old field. Yes: includes the pre-image of all fields. No (default): includes only the pre-image of the updated fields.

    Rules of the ordered messages delivered to RocketMQ.

    The ordering rule for messages written to the topic. See Rules of the ordered messages delivered to RocketMQ.

    Name of DTS producer group

    The producer group name for sending messages to the topic. Default: dts-producer-group. See Producers.

    Limits of RocketMQ messaging transactions per second (TPS)

    The maximum TPS when writing migrated data to the topic. Set this to a value greater than or equal to the maximum TPS of the ApsaraMQ for RocketMQ instance. The actual TPS may fluctuate slightly around this value. See Computing specifications and Limits on instance specifications.

    Whether to filter large size of records.

    Yes: skips messages larger than 4 MB. Select No only if all messages are within the 4 MB limit — oversized messages cause the migration task to fail.

    Capitalization of Object Names in Destination Instance

    The capitalization policy for database names, table names, and column names in the destination. Default: DTS default policy. See Specify the capitalization of object names in the destination instance.

    Source Objects

    Select databases or tables from the Source Objects section, then click the 向右小箭头 icon to add them to Selected Objects.

  2. Click Next: Advanced Settings and configure the following:

    Parameter

    Description

    Dedicated Cluster for Task Scheduling

    By default, DTS uses the shared cluster. Purchase a dedicated cluster to improve stability. See What is a DTS dedicated cluster.

    Retry Time for Failed Connections

    How long DTS retries after a connection failure. Valid values: 10–1,440 minutes. Default: 720 minutes. We recommend setting this to a value greater than 30 minutes.

    Retry Time for Other Issues

    How long DTS retries after DDL or DML operation failures. Valid values: 1–1,440 minutes. Default: 10 minutes. We recommend setting this to a value greater than 10 minutes. Must be less than Retry Time for Failed Connections.

    Enable Throttling for Full Data Migration

    Throttle full migration to reduce load on the source and destination. Configure Queries per second (QPS) to the source database, RPS of Full Data Migration, and Data migration speed for full migration (MB/s). Available only when Full Data Migration is selected.

    Enable Throttling for Incremental Data Migration

    Throttle incremental migration by configuring RPS of Incremental Data Migration and Data migration speed for incremental migration (MB/s). Available only when Incremental Data Migration is selected.

    Whether to delete SQL operations on heartbeat tables of forward and reverse tasks

    Yes: DTS does not write heartbeat SQL to the source, but the DTS instance may show latency. No: DTS writes heartbeat SQL, which may affect physical backup and cloning on the source.

    Environment Tag

    Optional tag for identifying the instance.

    Configure ETL

    Yes: enables the extract, transform, and load (ETL) feature. Enter data processing statements in the code editor. See What is ETL? and Configure ETL in a data migration or data synchronization task. No: ETL is disabled.

    Monitoring and Alerting

    Yes: configure alert thresholds and contacts to receive notifications when the task fails or latency exceeds the threshold. See Configure monitoring and alerting. No: no alerts.

Step 4: Run the precheck

Click Next: Save Task Settings and Precheck.

Note

To preview the API parameters for this task configuration, move the pointer over Next: Save Task Settings and Precheck and click Preview OpenAPI parameters before proceeding.

DTS runs a precheck before starting the migration task. If any items fail:

  • Click View Details next to the failed item, fix the issues, and click Precheck Again.

  • If an alert item can be ignored, click Confirm Alert Details, then click Ignore > OK > Precheck Again. Ignoring alerts may cause data inconsistency.

Step 5: Purchase the instance

  1. Wait until Success Rate reaches 100%, then click Next: Purchase Instance.

  2. On the Purchase Instance page, configure the following:

    Parameter

    Description

    Resource Group

    The resource group for the migration instance. Default: default resource group. See What is Resource Management?

    Instance Class

    Select an instance class based on the required migration speed. See Instance classes of data migration instances.

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

  4. Click Buy and Start, then click OK.

Verify the task is running

View the task on the Data Migration page:

  • Full data migration only: the task stops automatically when complete. The status shows Completed.

  • Full + incremental data migration: the incremental migration task runs continuously. The status shows Running.

Configure topic mapping

By default, all migrated data goes to the topic selected in the destination database configuration. Use object mapping to route data from specific tables to different topics, apply filter conditions, or configure partition keys.

Note

Table-level mapping takes priority over database-level mapping. If both are set, the database-level mapping is ignored.

  1. In the Selected Objects section, move the pointer over the object name.

  2. Right-click and select Edit.

  3. Configure the mapping in the dialog box that appears.

Database-level mapping

In the Edit Schema dialog box:

Parameter

Description

Schema Name

The topic to write data from this database. Defaults to the value of Topic in the destination database configuration. Changing this value routes all database data to the specified topic.

Select DDL and DML Operations to Be Synchronized

Select the SQL operations to include in incremental migration.

Table-level mapping

In the Edit Table dialog box:

Parameter

Description

Table Name

The topic to write data from this table. Defaults to the value of Topic in the destination database configuration. The topic must exist in the destination instance. Changing this value routes the table's data to the specified topic.

Filter Conditions

SQL conditions to filter the rows to migrate. See Specify filter conditions.

Select DDL and DML Operations to Be Synchronized

Select the SQL operations to include in incremental migration.

Partition Key

Available when Rules of the ordered messages delivered to RocketMQ. is set to Deliver data based on hash values of a specified column. Specify one or more columns as partition keys. DTS routes each row to the corresponding partition based on the hash value of the specified columns.

  1. Click OK.